Unlike using
Unprotect[In,Out];
Clear[In,Out];
Protect[In,Out];
to clean the occupied memory of the whole notebook, I want to clean the memory dynamically and accurately. That is, I want to clean out the specific memory I assign whenever I need.
For example, I wrote a loop and at each loop, it generates some intermediate results that need not to be stored and I just want to clean its corresponding memory at the end of each loop. How can I achieve it ?
For example,
For[i=0,i<=100,i++,
x=Array[#&,{1000,1000}];(*occupy many memory*)
Total[x];
(*after the Total operation, the x is worthless now
so I want to clean out its memory
How should I do*)
]
Module
, for example, or in some casesBlock
), then those variables will also be cleared automatically at the end (except in a few pathological cases which you are unlikely to hit in practice). $\endgroup$Out[n]
. You can control the number of stored results by adjustingHistoryLength
. $\endgroup$