I know that we can constrain the memory usage of certain computation using MemoryConstrained.

Is there a way to constrain the memory of each cell evaluation during the whole notebook session? Say for a particular session, I want to give Mathematica only 3 GB ram.

I want this because most of the time, unintentionally, I use up all my 4 GB of ram. And on Windows running out of memory hangs the system, so recently I have been unplugging the power a lot. :(

  • 2
    $\begingroup$ You can use $Pre. $\endgroup$
    – Kuba
    Commented Jan 30, 2015 at 22:28
  • 1
    $\begingroup$ Also $HistoryLength = 0 conserves some memory. $\endgroup$
    – ybeltukov
    Commented Jan 30, 2015 at 22:30

1 Answer 1


I think what Kuba is hinting at in his comment is something like this

$memLimit = 30000;
$Pre = 
    MemoryConstrained[expr, $memLimit, Print["memory limit exceded"]], 

Clear @ t; t = Table[i^15, {i, 450}]; ByteCount[t]
Clear @ t; t = Table[i^15, {i, 1000}]; ByteCount[t]

memory limit exceded


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.