This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Memory Usage  /
Share

  • Share[ expr ] changes the way expr is stored internally, to try and minimize the amount of memory used.
  • Share[ ] tries to minimize the memory used to store all expressions.
  • Share works 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.
  • See the Mathematica book: Section 2.13.4.
  • See also: MemoryInUse, ByteCount.
  • Related package: Utilities`MemoryConserve`.

    Further Examples

    Here is the amount of memory in use at the time this expression was evaluated.

    In[1]:=

    Out[1]=

    This creates a very large data structure of interpolating functions.

    In[2]:=

    You can see that almost 3/4-megabyte of memory has been taken up in computing and then storing this result.

    In[3]:=

    Out[3]=

    When you run Share, it reports back how much memory was recovered.

    In[4]:=

    Out[4]=

    Here is the amount of memory in use after running Share.

    In[5]:=

    Out[5]=