フィルターのクリア

Clearing variables does not clear RAM

1 回表示 (過去 30 日間)
Trevor Harris
Trevor Harris 2016 年 4 月 18 日
回答済み: Philip Borghesani 2016 年 4 月 25 日
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

回答 (2 件)

Image Analyst
Image Analyst 2016 年 4 月 18 日
What do you see if you put the memory command before and after the clear
memory
clear('testTemp');
memory
  3 件のコメント
Image Analyst
Image Analyst 2016 年 4 月 18 日
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.
Trevor Harris
Trevor Harris 2016 年 4 月 25 日
My apologies. See attached.

サインインしてコメントする。


Philip Borghesani
Philip Borghesani 2016 年 4 月 25 日
Some questions and thoughts:
  1. 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).
  2. 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.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by