How to clear memory allocated from functions

6 visualizzazioni (ultimi 30 giorni)
Dimitrios Passas
Dimitrios Passas il 18 Mag 2017
Modificato: Dimitrios Passas il 18 Mag 2017
Dear all,
i am running an optimization code for various operating points that contains multiple subfunctions, which generate and operate with various variables but only return those required. Is there a way to have the allocated memory of those variables cleared. Whenever I am running the code the commited Memory stacks up and the range of operating points that I can examine is restricted.
Thank you in advance.

Risposte (2)

Jan
Jan il 18 Mag 2017
Matlab clears all locally created variables, which are not replied or persistent, automatically, if the function is left. Therefore it is only a waste of time to insert some clear commands at the end of the functions.
Do you pre-allocate all arrays properly or do they grow iteratively?
How do you check that "the commited Memory stacks up"? Note that Matlab can request memory from the OS, but it is not immediately released, when the variable is deleted. There is a memory fragmentation also, if multiple small arrays are stored distributed over the memory, such that there is no large contiguos block of free memory anymore.
So please explain the problem you observe more exactly.
  1 Commento
Dimitrios Passas
Dimitrios Passas il 18 Mag 2017
Modificato: Dimitrios Passas il 18 Mag 2017
Regarding the committed Memory, I monitor it from the Task Manager and it slowly fills up as the code is running; and all my arrays are pre-allocated.
The code consists of a part that runs a function (containing more sub functions), that returns more or less 100MB of arrays and structures. Based on some criteria, irrelevant to the problem, I am then calculating a performance value- a number. I then alter some of the conditions each time and rerun the initial function and in case the performance value is better I store the value and the location to a structure. The structure is edited every time a better solution is found. The code runs flawlessly, computing each operating case and it only stops, in the case I have too many operating points and the committed memory reaches the ceiling which in my case is around 32GB.
My base work-space is basically empty.

Accedi per commentare.


KSSV
KSSV il 18 Mag 2017
Doc clear
If you know the name of variable you an use
clear name

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by