Do Matlab structures leak memory?
Ältere Kommentare anzeigen
I am currently processing data files that are so large that I can fit them to memory only one per at a time. My problem is that if I use structures for storing the data, I keep getting out of memory errors. I managed reproduce the problem with the following code:
%%This runs ok first time, but gives "Out of memory" error on the second run
clear;
mult = 200;
a = zeros(mult * 1000, 1000);
%%The following code seems to leak memory
clear a;
for i = 1:mult
s(i).sa = rand(1000, 1000);
end
s_copy = s;
I was wondering if anyone can reproduce this problem or is my computer broken? You might need to adjust the 'mult' to a larger value to get the code reserve enough memory to cause the problem.
1 Kommentar
Klaus Förger
am 19 Jun. 2015
Antworten (2)
B.k Sumedha
am 18 Jun. 2015
0 Stimmen
I suggest you to try:
File > Preferences > General > Java Heap Memory.
Then you can increase the amount of memory beyond the default value of 196 MB. Hope this helps.
3 Kommentare
Klaus Förger
am 18 Jun. 2015
B.k Sumedha
am 18 Jun. 2015
Do you really need that much of data to be multiplied?
Klaus Förger
am 18 Jun. 2015
Philip Borghesani
am 18 Jun. 2015
0 Stimmen
This is not a leak and has nothing to do with Java heap. This code is not using the Java heap.
The problem is that you are fragmenting the virtual address space on a 32 bit version of MATLAB. Use the memory command to to view available and largest memory blocks along with how much memory MATLAB is using.
The best solution is to use 64 bit MATLAB.
3 Kommentare
Klaus Förger
am 18 Jun. 2015
Philip Borghesani
am 18 Jun. 2015
The problem still feels like a fragmentation issue. The best solution should just be to increase the size of your swap partition. (You do have one and it is enabled?) these memory sizes seem small for a 64 bit machine is this a VM? I ran this code hundreds of times on my machine with no visible leak.
Klaus Förger
am 19 Jun. 2015
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!