フィルターのクリア

Matlab doesn't free memory

9 ビュー (過去 30 日間)
TheBeginner
TheBeginner 2013 年 7 月 12 日
コメント済み: Nick 2020 年 3 月 17 日
Hi,
I have a function that creates a quite big array (~ 200 kbytes)in a loop.
At first the function works well, my array is well created, but after a dozen loops, Matlab says i'm out of memory.
I have been checking my memory and it seems between each loop, even though I free all the memory (clear all, clc etc...), Matlab still occupies a significant part of the memory...
I have found some topics discussing that point, and it seems to be "normal", but I didn't find a solution, except from relaunching Matlab, which is not satisfying.
Any idea on how to indeed free the memory?
Thank you
  1 件のコメント
Jan
Jan 2013 年 7 月 12 日
Avoid the brute clearing by "clear all, clc", although it is obviously a fashion to use it. Reloading the functions from the disk wastes a lot of time afterwards, and the deleteing of all debugger breakpoints is a very bad idea.

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

回答 (2 件)

Ilham Hardy
Ilham Hardy 2013 年 7 月 12 日
  • Is the array uniform in size?
  • Do you preallocate the array first?
  • Create several "checkpoints" in your for loop by saving the workspace to the disk.
  3 件のコメント
Ilham Hardy
Ilham Hardy 2013 年 7 月 12 日
As far as i understand, as long as you preallocate and use the same name for the array during the for-loop, it will occupies the same memory region during the process.
Hope it helps, IH
Nick
Nick 2020 年 3 月 17 日
I have the same issue.
I am reading in data files, processing and plotting them and repeating with new data files.
Having traced through my code while watching performance manager I see that the memory which doesn't clear is the memory that was used whuilst creating plots inside figures (there are many data points). If I create lots of plots, then the amount of used memory goes up and remains up even after the variables displayed in the plots have been cleared and the figures closed. Eventually matlab is using so much of my PC's 16GB of RAM that it can't find space to load the next data file.
Tried clear all, close all, close all hidden .. to no avail.
The only way to clear that redudant plot data is to shut down matlab and then restart .. bit "$£% really.

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


Jan
Jan 2013 年 7 月 12 日
編集済み: Jan 2013 年 7 月 13 日
200kB is not big in the times of 8 GB machines. Therefore a missing pre-allocation seems to be more likely a reason for your problems. Without seeing the relevant part of the code it is not possible to examine this. But such an omitted pre-allocation does not fill the memory with values (because the not longer used memory chunks are freed), but the memory is fragmented such that the OS cannot allocate free contiguous blocks anymore.
As usual installing more RAM and running a 64-Bit version of Matlab and the OS are fundamental and basic strategies to get rid of "out-of-memory" errors.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by