Matlab doesn't release memory when function finishes
13 次查看(过去 30 天)
显示 更早的评论
I've checked all documentation I can find to solve my problem and nothing works. Matlab grabs memory and doesn't let it go. Clear doesn't work, pack doesn't help, I've tried clear functions... Basically, once the memory is caught, the only way that I can release it is to quit matlab and start over. I am creating (and closing) large numbers of netcdf files. Processing 250 of these uses only .6% of my memory. Multiply this times 80000 files and you can see the problem. It either causes matlab to crash (the preferred option since I can at least restart it where it left off) or freezes the linux VM causing delays while I try to get it rebooted. I've tried to use a function to perform this task because the end of a function is supposed to release the memory required but I'm still using 5.1% after starting the exercise at 4.5%. I have 2gb of swap and 7gb of usable memory which should be more than sufficient since each file takes only a tiny fraction of this but if it doesn't get released, it just keeps building up until.... Any advice would be gratefully appreciated!
0 个评论
回答(1 个)
Image Analyst
2014-10-14
Try manually deleting large variables just before you exit from the function with clear().
clear('bigHonkingArray', 'anotherWhopperArray', 'motherOfAllArrays', 'OMGItsHuge');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!