Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Bug introduced in 11.0 and persisting through 11.1


It looks like Mathematica 11 stack tracing feature (see red ellipsis in front of any warning message) prevents 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 stack trace an thus prevent 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 messages?

share|improve this question
1  
The memory leak is reproduced with version 11.0.1 on Windows 7 x64. With version 10.4.1 there is no memory leak. – Alexey Popkov 10 hours ago
1  
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. – user6014 10 hours ago
3  
    
@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. – Alexey Popkov 9 hours ago
    
@AlexeyPopkov you see, I missed the point. Let me delete my confusing comments – Kuba 9 hours ago

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.

share|improve this answer

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.

share|improve this answer
    
Also works for version 11.1, which is just now being released. – bbgodfrey 3 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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