Make the best use of your system's memory in Mathematica

In Mathematica, you can use ClearAll to recover memory associated with calculations you no longer need. For this to work, you must also remove your output history with Unprotect and Clear[Out].

Mathematica will use some amount of memory to start up:

 In[1]:= MemoryInUse[] Out[1]= 812448

If you create a large matrix (for example, t) but suppress the output, and then check the memory again, you'll see the memory used increases:

 In[2]:= t = Table[Random[], {1000}, {1000}]; In[3]:= MemoryInUse[] Out[3]= 20843256

If you clear the variable (for example, t) from memory, the memory used increases slightly again:

 In[4]:= Clear[t] In[5]:= MemoryInUse[] Out[5]= 20844712

However, if you also clear the output from memory, you reduce the memory used to nearly the minimal amount:

 In[6]:= Unprotect[Out] Out[6]= {Out} In[7]:= Clear[Out] In[8]:= Protect[Out] Out[8]= {Out} In[9]:= MemoryInUse[] Out[9]= 827120

For more, see Statistical and mathematical software available at IU.

If you have questions about using statistical and mathematical software at Indiana University, contact Research Analytics.

This is document adiv in the Knowledge Base.
Last modified on 2019-01-31 15:57:53.

Contact us

For help or to comment, email the UITS Support Center.