Matlab is so nice but How I wish it can manage physical memory properly. It does not seem to know how to track the memory it allocates, It says 'out of memory' even when all other variables are cleared. If you restart it and try the same thing again it works but not for very long before it says 'out of memory' once again. It almost seem like the clearing variable has not effect other making the variable invisible.
Its so crazy because pack() which is meant to rescue the situation also gives out of memory error after it has deleted all your variables containing valuable data.
Please if anybody got a solution let me know, I really don't wanna throw this computer through the window if it says 'out of memory' just one more time!!!!!!!!!
Hopefully the computer geniuses at Mathworks will help us clear there footprints
You should not trough the computer out of the window, even if says "out of memory". You might hurt someone in the street.
Matlab is not perfect, but it mostly recovers memory well. Speculations:
You explained, that even pack fails with an out-of-memory error. pack stores the currently known variables in a MAT file, clears the memory and reloads the data. When this reloading fails, I cannot imagine how the value could fit into the memory before saving.
Exhausting the computer's memory is a general problem and not caused by Matlab itself. The same will happen in any programming language. The only strong solution is installing more RAM and running a 64 bit system, and installing even more RAM. Using smaller data types can help also, but this is a standard procedure and should be applied even if the computer does not crash to save resources.
You can try feature memstats periodically in your function and it might provide a clue as to what is growing? Maybe use the windows system monitors? cntrl-alt-delete to task manager, then performance tab and use the resource monitor button at the bottom? There are a few views of memory and maybe something else is growing? You went through the "doc Resolving "Out of Memory" Errors"?
A stupid suggestion, but maybe it will spur some "outside of the box" thinking, you might already be doing some of it. Is it possible to save your important data to file, clear everything and reload and restart from where you saved? There are apps out there for windows which will run
If your plot has a lot of data in it and you are using hold, it might be filling up memory? You can try just updating your plot with the latest data. You can just running it without the plot and see how much longer it runs? This is a really helpful discussion: http://undocumentedmatlab.com/blog/plot-performance/
>> feature memstats
Physical Memory (RAM): In Use: 7142 MB ( 1be6bf000) Free: 17430 MB ( 4416d7000) Total: 24573 MB ( 5ffd96000) Page File (Swap space): In Use: 7302 MB ( 1c86f1000) Free: 41842 MB ( a3726b000) Total: 49145 MB ( bff95c000) Virtual Memory (Address Space): In Use: 8766 MB ( 223e7f000) Free: 8379841 MB (7fddc161000) Total: 8388607 MB (7fffffe0000) Largest Contiguous Free Blocks: 1. [at 228010000] 8375214 MB (7fcbae30000) 2. [at 7feff031000] 4110 MB ( 100ec3000) 3. [at 17c030000] 63 MB ( 3fd0000) 4. [at 7feebfbb000] 47 MB ( 2fe5000) 5. [at 13e400000] 28 MB ( 1c00000) 6. [at 7feeefb7000] 24 MB ( 18e9000) 7. [at 7fee4fec000] 24 MB ( 1844000) 8. [at 7bc66000] 17 MB ( 11aa000) 9. [at 7fef0920000] 14 MB ( ef0000) 10. [at 7fee9139000] 14 MB ( ed7000) ======= ========== 8379561 MB (7fdca946000)
So after whinging at everybody about my life and how is all ruined by this 32bit computer and matlab and memory and global warming, yeah, I just got sorted with a 64bit machine runing 64bit matlab. This thing is gold mine. Life is good!!!
Thanks to everyone for all your suggestions, they were all useful!