Do Matlab structures leak memory?
古いコメントを表示
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.
回答 (2 件)
B.k Sumedha
2015 年 6 月 18 日
0 投票
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 件のコメント
Klaus Förger
2015 年 6 月 18 日
B.k Sumedha
2015 年 6 月 18 日
Do you really need that much of data to be multiplied?
Klaus Förger
2015 年 6 月 18 日
Philip Borghesani
2015 年 6 月 18 日
0 投票
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 件のコメント
Klaus Förger
2015 年 6 月 18 日
Philip Borghesani
2015 年 6 月 18 日
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
2015 年 6 月 19 日
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!