Trying to solve a differential equation numerically, I noticed that Mathematica used up all RAM to the extent that my operating system (Windows 10) lost responsiveness and hung up.

As a result I had to restart my machine, losing all unsaved progress in the Mathematica notebook I was working on.

Is there a way to limit the RAM amount Mathematica can possibly access during a calculation?

  • 4
    $\begingroup$ You can use MemoryConstrained to constrain the amount of memory a computation takes. $\endgroup$ – Carl Woll Apr 9 at 16:07
  • $\begingroup$ @CarlWoll Thanks! I wonder if there is a setting that applies this to the entire kernel session? $\endgroup$ – Kagaratsch Apr 9 at 16:10

You can use MemoryConstrained to set a memory constraint for an evaluation. You can use $Pre to set a memory constraint for all evaluations:

$Pre = Function[
    MemoryConstrained[#, 2000000000-MemoryInUse[]],

For example:




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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