Message Boards Message Boards

Free memory in Mathematica?

Posted 8 years ago

Greetings! I have problems with memory management. Some programs ran out of memory. I try to free memory using Clear and other commands but they do not seem to work. In particular there is one example in the memory management tutorial in the Mathematica help that I tried on my computer and it did not work. I reproduced this particular example below. Anyone has an idea how to make it work? Thank you, Petre

Additional memory is needed to store the list.
In[3]:= MemoryInUse[]
Out[3]=  989616
This list is kept because it is the value of Out[2]. If you clear Out[2], the list is no longer needed.
In[4]:= Unprotect[Out]; Out[2] =.
The memory in use goes down again.
In[5]:= MemoryInUse[]
Out[5]=  954408
POSTED BY: Petre Logofatu
2 Replies

Try to set:

$HistoryLength = 1 (or 0)

rather than clearing Out manually. But do so at the start of your session. This will only store one 'Out' not more...

Basically, every time you input something and run it, it will be stored in Out[xyz] where xyz is a number. By default, $HistoryLength = infinity, such that everything that is outputted is stored inside the memory, gradually building up over time. By setting HistoryLength to some low number, it will only store the last xyz number of outputs...

The example will depend on what you had for input and can vary orders of magnitudes...

POSTED BY: Sander Huisman

Thank you very much. It has been very helpful. I was able to push the envelope further.

POSTED BY: Petre Logofatu
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract