How to clear memory allocated from functions
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Jan
2017-5-18
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!