3
$\begingroup$

This question already has an answer here:

An hour ago, I had to hard reset my laptop again because Mathematica froze the system again. When import a large file or make a mistake that produces huge arrays with complicated entries etc., I often see that the system becomes unresponsive. Holding the power button for seconds seems to be the only solution.

I was forced to do so about 20 times in recent 3 months, because of a project I was working at. Today, chkdsk had to start already when Windows was starting which I think is creepy. No errors found on the disk, thank God.

Is there a way to constrain this behavior so that it doesn't become hopeless? Some setting which makes Mathematica say "I give up, low memory" instead of doing the impossible and suicidal caching?

$\endgroup$

marked as duplicate by C. E., Michael E2, Öskå, Oleksandr R., m_goldberg Aug 22 '14 at 13:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    $\begingroup$ I believe this is a duplicate of: (2789). Also I have had some success using this: $Pre = Function[Null, MemoryConstrained[Unevaluated @ #, 2^32, "Memory Exceeded"], HoldAll] (see (30600)) -- it doesn't always work but it seems to most of the time. $\endgroup$ – Mr.Wizard Aug 22 '14 at 6:53
  • $\begingroup$ You may have to be patient, but normally Windows does not actually freeze when this happens. If you can stand to wait for a few minutes (possibly up to 10), it's a better alternative than switching off the computer. Obviously it's better still to prevent this situation occurring in the first place, but that's not always possible. $\endgroup$ – Oleksandr R. Aug 22 '14 at 11:02
  • $\begingroup$ LOL, right, I actually got out of the doom after 10 minutes once. But it seems so uncertain... $\endgroup$ – Luboš Motl Aug 22 '14 at 11:52
3
$\begingroup$

Use MemoryConstrained

MemoryConstrained[yourCode, memoryLimit, actionOnMemoryLimitOverflow]
$\endgroup$

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