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?
hugeTempVar$541
, it does show the codehugeTempVar$541 = ConstantArray[1, 1000]
what doesn't require keeping the actual variablehugeTempVar$541
. $\endgroup$