Out of memory frustration
18 views (last 30 days)
Show older comments
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
1 Comment
Yao Li
on 9 Apr 2013
try to improve your algorithm. For example, if you want to load data from an Excel or text file, try to load only a few columns or rows at a time instead of loading all the data as a large matrix.
Answers (5)
per isakson
on 9 Apr 2013
Edited: per isakson
on 9 Apr 2013
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:
- do you have some persistent data in a function or object?
- there are tools to inspect memory use at the File Exchange and at Undocumented Matlab, e.g. Undocumented profiler options
- Use Task Manager (Windows) to inspect the memory use
- you have found a bug (memory leak). Report to the tech-support with all details.
2 Comments
per isakson
on 9 Apr 2013
>> [48 * 1536 * 60]*8/1e6
ans =
35.3894
>>
35MB is not the problem.
Jan
on 9 Apr 2013
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.
4 Comments
Jan
on 11 Apr 2013
@bethel: It is not the question, if pack should be designed differently. The builtinin commands works as advertised, and it cannot perform magic. If the memory is "really" free'd depends on the operating system also. Here Windows7 is much smarter than e.g. XP. When your program calls Mex functions or DLLs, which produce memory leaks, restarting Matlab is the only way to free the memory, while pack cannot access the memory (otherwise it would not be a "leak").
Of course a simulation can run for years without exahsuting the memory, when it is carefully designed, or it can fill the memory in milliseconds. Such problems must be solved by the programmer (and the admin, who installs more RAM!), and neither Matlab nor the OS can catch this automagically.
I do not see any reason, why realtime simulation should run worse under 64 bit. When you have troubles with the limited memory, 64 bit (and more RAM) will definitely better than any drawbacks you expect for the actually more powerful system.
Mike
on 9 Apr 2013
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)
ans =
8782048591872
Walter Roberson
on 9 Apr 2013
Are you deleting all the graphics objects as well ?
3 Comments
Jan
on 9 Apr 2013
If you have one figure, but create new objects e.g. by image() without deleting the formerly created objects, the memory will be exhausted after a certain number of operations. None of the clearing commands would be helpful then. My impression is, that clearing ios useful under rare conditions only in Matlab.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!