Bug was introduced in 11.0 and persisting through 11.1

It looks like the Mathematica 11 stack tracing feature (see red ellipsis in front of any warning message) prevents the garbage collector from removing temporary variables. For example, the following code leaves three copies of hugeTempVar in memory after each evaluation.

test[a_]:= Module[{hugeTempVar},
    hugeTempVar = ConstantArray[a, 1000];
    a/0; (* some code which produces a message *)

Table[test[i], {i, 1, 10}];


If one removes message-producing code a/0 there is no memory leak.

In this particular example, one can also use ParallelTable to enable old-style messages without a stack trace and thus prevent a memory leak.

I don't want to disable messages, because they provide important diagnostic information.

Is there a possibility to disable stack tracing, but keep the messages?

  • 2
    $\begingroup$ The memory leak is reproduced with version 11.0.1 on Windows 7 x64. With version 10.4.1 there is no memory leak. $\endgroup$ Mar 17, 2017 at 14:42
  • 2
    $\begingroup$ I would suggest filing a report with Wolfram on this, I think it's annoying enough that it's worth bringing to their attention and letting them decide. $\endgroup$
    – ktm
    Mar 17, 2017 at 15:13
  • 4
    $\begingroup$ See here: mathematica.stackexchange.com/q/123965/12 $\endgroup$
    – Szabolcs
    Mar 17, 2017 at 15:13
  • $\begingroup$ @Kuba The "Stack Trace ..." window which can be opened from the ellipsis in front of the warning message doesn't show the value of hugeTempVar$541, it does show the code hugeTempVar$541 = ConstantArray[1, 1000] what doesn't require keeping the actual variable hugeTempVar$541. $\endgroup$ Mar 17, 2017 at 15:26
  • $\begingroup$ @AlexeyPopkov you see, I missed the point. Let me delete my confusing comments $\endgroup$
    – Kuba
    Mar 17, 2017 at 15:28

2 Answers 2


Is there a possibility to disable stack tracing, but keep messages?

Internal`$MessageMenu = False

reverts back to the old messages. Seems to do the trick and prevent the leak from my testing.


Analysis current as of Mathematica version 11.0.1 and 11.1.0.

We can disable the Show Stack Trace item in the new message menu as follows:

MessageMenu`Dump`$IncludeStack = False;

The reference to MessageMenu`$PruneStack is there to ensure that the message menu packages have been autoloaded (otherwise our setting will be lost should the packages be loaded later).

Stack information is stored as down-values on the symbol MessageMenu`MessageStackList. We can reclaim any memory from earlier messages by executing ClearAll on this symbol. We can also inspect these down values to verify that the $IncludeStack setting is taking effect.

  • $\begingroup$ Also works for version 11.1, which is just now being released. $\endgroup$
    – bbgodfrey
    Mar 17, 2017 at 21:26

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.