Matlab doesn't release memory when function finishes

13 Ansichten (letzte 30 Tage)
Ann
Ann am 14 Okt. 2014
Kommentiert: Ann am 15 Okt. 2014
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!

Antworten (1)

Image Analyst
Image Analyst am 14 Okt. 2014
Try manually deleting large variables just before you exit from the function with clear().
clear('bigHonkingArray', 'anotherWhopperArray', 'motherOfAllArrays', 'OMGItsHuge');
  1 Kommentar
Ann
Ann am 15 Okt. 2014
Unfortunately, there aren't any large variables. My largest variable (and in a function that in theory clears as soon as you exit the function anyway) is a structure holding 3.6mb. Clearing that (within the function) doesn't have any effect. And neither clear('all') nor 'clear' change the memory grabbed by Matlab. The only thing that had any effect was clear classes which returned a whopping 0.4% of memory. but processing another 258 files still leaves me at 5.9% and climbing (now 7.1% after another 265 files). That 0.4% returns immediately when I restart the run which makes sense if the classes restart. So - still no idea how to recapture the memory but I've decided to run the larger job and keep grabbing screenshots to see where it runs out of puff and either freezes or crashes.
Any and all advice happily tried! Thanks - Ann.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by