Memory Issues: Almost like clear doesn't fully work
이전 댓글 표시
I am running 32b vista, Matlab 2009a. The machine has 4GB of RAM installed, PAE & 3G switch activated. the machine is dedicated to MATLAB and doesn't run anything else.
I have code that reads and writes data from disk. Data is stored in the form of txt files. There are thousands of text files around 200MB each in size. The code loads the text file into RAM processes it and then writes it back to disk.
Each load is done within a loop
for i = 1: numFiles
loadAndWriteData(file(i))
end
function loadAndWriteData(file)
load file
do stuff
save file
clear file (and all other variables I can see lurking around)
end
hence any RAM intensive processes are done in loadAndWriteData.m This returns on each call of the for loop.
I use memory.m to inspect the memomry availble to me. I see that after a few runs around the available memory starts dropping off. Then Matlab crashes with an out of RAM error.
I would have thought that as the function is returning each time around the loop, I would be nicely clearing everything in RAM.
What I am doing wrong? Any help gratefully received. thank you.
채택된 답변
추가 답변 (3개)
mathworks2011
2011년 4월 21일
0 개 추천
댓글 수: 2
Jason Ross
2011년 4월 21일
Your suggestion of quitting MATLAB and starting again isn't so nonsensical. If this program was amenable to using functions from the parallel computing toolbox, you can set the RestartWorker on the job object to do exactly that.
http://www.mathworks.com/help/toolbox/distcomp/restartworker.html
mathworks2011
2011년 4월 21일
Matt Fig
2011년 4월 21일
How are you clearing the files? Are you using FCLOSE and checking the return variable?
EDIT
I am not certain that clearing the file identifier will close the file. I don't see it in the documentation...
fid = fopen('myfile')
clear fid % Is the file in memory or not?
fclose(fid) % Does using this instead of clear help???
댓글 수: 5
mathworks2011
2011년 4월 21일
mathworks2011
2011년 4월 21일
Matt Fig
2011년 4월 21일
O.k., so you are already using FCLOSE. That is what I meant in my original question. Why not just use a script instead of functions? That way you can have access to the pack command.
You could inline the contents of loadAndWriteData to a script which has the FOR loop.
That way you could then clear and pack however often you need...
mathworks2011
2011년 4월 21일
Matt Fig
2011년 4월 21일
A script is an M-file which has no keyword: function in it. For example, this is would be a function M-file:
function B = mysquare(A)
B = A.^2;
and this would be a script M-file:
B = A.^2;
The script will actually execute in the base workspace, and so can call PACK. To change a function to a script, simply copy and paste all of the code into a new M-file. Note that scripts can call function M-files, so just put the bare-bones in a script, then you can call PACK and other command line functions.
aasim Azooz
2011년 4월 22일
0 개 추천
Try this for i = 1: numFiles loadAndWriteData(file(i)) clear all end
if it does not work, you may have a virus in your computer. It happened with me. everything went fine after I scanned my PC for viruses. good Luck Aasim Azooz
카테고리
도움말 센터 및 File Exchange에서 Language Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!