This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Add-ons / Standard Packages / Utilities  /


On computers that have small amounts of installed memory, Mathematica's performance will begin to suffer after carrying out many memory-intensive calculations. This package optimizes Mathematica's use of memory by automatically executing the kernel command Share[] whenever memory usage increases by a specified amount.
Share[] tries to minimize the memory used to store all expressions by sharing the storage of common subexpressions between different parts of an expression, or different expressions. Using Share[] will never affect the results you get from Mathematica. It may, however, reduce the amount of memory used, and in many cases also the amount of time taken. Note, however, that the Share[] command itself may take some time to run.

Commands for memory conservation.

  • This loads the package.
  • In[1]:= <<Utilities`MemoryConserve`

  • When memory usage has increased by $MemoryIncrement bytes Share[] will be run automatically.
  • In[2]:= $MemoryIncrement


  • This generates a large list containing multiple copies of the same expression.
  • In[3]:= Table[ ToString[0], {2^15} ];

  • As you do subsequent calculations, Share[] is called and a significant amount of memory is freed up. The amount freed will vary from one computer system to another.
  • In[4]:= Length[ % ]

    MemoryConserve::start: Running Share[] to conserve memory.

    MemoryConserve::end: Finished running Share[]; 586400 bytes of memory freed.


  • This stops automatic memory conservation.
  • In[5]:= Off[ MemoryConserve ]

  • This restarts automatic memory conservation.
  • In[6]:= On[ MemoryConserve ]