32
$\begingroup$

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 *)
    a
    ];

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

Names[$Context<>"*$*"]

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?

$\endgroup$
  • 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$ – Alexey Popkov Mar 17 '17 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$ – user6014 Mar 17 '17 at 15:13
  • 4
    $\begingroup$ See here: mathematica.stackexchange.com/q/123965/12 $\endgroup$ – Szabolcs Mar 17 '17 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$ – Alexey Popkov Mar 17 '17 at 15:26
  • $\begingroup$ @AlexeyPopkov you see, I missed the point. Let me delete my confusing comments $\endgroup$ – Kuba Mar 17 '17 at 15:28
27
$\begingroup$

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.

$\endgroup$
24
$\begingroup$

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`$PruneStack;
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.

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

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.