How to clear memory allocated from functions
6 views (last 30 days)
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.
0 Comments
Answers (2)
Jan
on 18 May 2017
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
See Also
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!