7
$\begingroup$

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. :(

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

1 Answer 1

7
$\begingroup$

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

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

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

memory limit exceded

$\endgroup$

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.