I'd like to make a graphical version of
Dynamic[Refresh[MemoryInUse[], UpdateInterval -> 1]]
A naive implementation would be something like:
miu = {};
Dynamic[Refresh[ListPlot[AppendTo[miu, MemoryInUse[]]], UpdateInterval -> 1]]
(Evaluate Quit[]
, or equivalently, choose Evaluation > Quit Kernel
, to stop it.)
This code produces a very lousy memory monitor, because it, all by itself, causes the memory to grow steadily. IOW, it's a honking memory leak.
I tried something that I thought would be more conservative:
nReadings = 100;
miu = Table[0, nReadings];
i = 0;
updatemiu[] := Module[{},
i = Mod[i, nReadings] + 1;
miu[[i]] = MemoryInUse[];
Join[Drop[miu, i], Take[miu, i]]
]
Dynamic[Refresh[ListPlot[updatemiu[]], UpdateInterval -> 1]]
This one leaks too, even though, in contrast to the previous version, it gets its data from a fixed-size list.
Is there a reliable way to cap the amount of memory used by this monitor?
UpdateInterval
option. I would be satisfied with an interval of 30 sec. rather than the 1 sec. used in the example. I would also consider raising the memory limit from 2 GB to something like 8GB. $\endgroup$TrackedSymbols :> {}
toDynamic
and changeMemoryInUse[]
toN@MemoryInUse[]
your last code block does work without "leakage". $\endgroup$