In Mathematica, how can I make the best use of my system's memory?

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 (e.g., 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 (e.g., 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. Research Analytics is located on the IU Bloomington campus at Woodburn Hall 200; staff are available for consultation Monday-Friday 9am-noon and by appointment.

This is document adiv in the Knowledge Base.
Last modified on 2018-05-30 15:27:00.

Contact us

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