MemoryConstrained

MemoryConstrained[expr, b]
evaluates expr, stopping if more than b bytes of memory are requested.

MemoryConstrained[expr, b, failexpr]
returns failexpr if the memory constraint is not met.

DetailsDetails

ExamplesExamplesopen allclose all

Basic Examples (2)Basic Examples (2)

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Run a command until a memory limit is exceeded:

In[1]:=
Click for copyable input
Out[1]=

The loop ran until memory allocation for the result of Range exceeded the limit:

In[2]:=
Click for copyable input
Out[2]=
New in 1 | Last modified in 6
New to Mathematica? Find your learning path »
Have a question? Ask support »