How to clear memory allocated from functions
Show older comments
Dear all,
i am running an optimization code for various operating points that contains multiple subfunctions, which generate and operate with various variables but only return those required. Is there a way to have the allocated memory of those variables cleared. Whenever I am running the code the commited Memory stacks up and the range of operating points that I can examine is restricted.
Thank you in advance.
Answers (2)
Jan
on 18 May 2017
2 votes
Matlab clears all locally created variables, which are not replied or persistent, automatically, if the function is left. Therefore it is only a waste of time to insert some clear commands at the end of the functions.
Do you pre-allocate all arrays properly or do they grow iteratively?
How do you check that "the commited Memory stacks up"? Note that Matlab can request memory from the OS, but it is not immediately released, when the variable is deleted. There is a memory fragmentation also, if multiple small arrays are stored distributed over the memory, such that there is no large contiguos block of free memory anymore.
So please explain the problem you observe more exactly.
1 Comment
Dimitrios Passas
on 18 May 2017
Edited: Dimitrios Passas
on 18 May 2017
KSSV
on 18 May 2017
Doc clear
If you know the name of variable you an use
clear name
Categories
Find more on Function Creation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!