Memory Issues: Almost like clear doesn't fully work
5 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
更多回答(3 个)
mathworks2011
2011-4-21
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
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 个评论
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!