Clearing variables does not clear RAM
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hey all,
So I'm working with some large file and I'm extracting data from said files using the code below:
for iTest = 1:length(testFiles)
disp(['Loading Test ', num2str(iTest), ' of ', num2str(length(testFiles))])
testTemp = load([pwd, '\RESULTS\', testFiles{iTest}, '\', testFiles{iTest}, '.mat']);
segments = size(testTemp.dataStruc(chan2idx(testTemp.dataStruc,'PITCH')).data.segments,1);
for iSeg = 1:length(segments)
pitchMean(end+1) = testTemp.dataStruc(chan2idx(testTemp.dataStruc,'PITCH')).data.(['S', num2str(iSeg)]).mean.data;
fuelMean(end+1) = testTemp.dataStruc(chan2idx(testTemp.dataStruc,'FUEL_COMP')).data.(['S', num2str(iSeg)]).mean.data;
speedMean(end+1) = testTemp.dataStruc(chan2idx(testTemp.dataStruc,'SPEED')).data.(['S', num2str(iSeg)]).mean.data;
end
clear testTemp
end
All well and good. The only issue is that the clear testTemp at the end of every loop does not seem to clear the memory. My ram keeps climbing! The removal of testTemp is verified by the whos command. See the attached screenshot which illustrates this odd behavior. Any ideas as to what may be going on?
It may also be worth noting that this behavior happens to me all the time, not just in loops. I'm only now posting out of frustration.
Thanks! Trevor
0 comentarios
Respuestas (2)
Image Analyst
el 18 de Abr. de 2016
What do you see if you put the memory command before and after the clear
memory
clear('testTemp');
memory
3 comentarios
Image Analyst
el 18 de Abr. de 2016
Trevor, you can't do it from the command line - the variable has already been cleared by that point.
Put those lines of code in your script, replacing the one clear you have now, just before the end of your for loop. Then show us what gets displayed in the command window.
Philip Borghesani
el 25 de Abr. de 2016
Some questions and thoughts:
- Task manager is not a very good way to track memory use by an application. I suggest looking at something like process explorer and just looking at the private bytes graph for the MATLLAB task using process explorer from sysinternals (Microsoft).
- What is in these mat files? Are there any globals? please show us the output of whos -file for one (the largest?) of these files.
Your code is growing 3 arrays in each loop, doing so is fragmenting memory, that along with loading large mat files could cause the symptoms you are seeing due to memory fragmentation.
0 comentarios
Ver también
Categorías
Más información sobre Variables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!