在Mathematica中分析内存使用情况 [英] Profiling memory usage in Mathematica
问题描述
除了为他们的Eclipse插件(mathematica workbench,iirc)支付$$费用外,是否有其他方法可以描述数学内核的内存使用情况(降至单个变量)?
Is there any way to profile the mathkernel memory usage (down to individual variables) other than paying $$$ for their Eclipse plugin (mathematica workbench, iirc)?
现在,我完成了一个程序,该程序需要多个GB的ram,但是存储的唯一内容最多应该是〜50MB的数据,但是mathkernel.exe倾向于保持〜1.5GB(基本上,就是就像Windows会给出的那样).除了保存我需要的数据并每次退出内核之外,还有什么更好的方法来解决这个问题?
Right now I finish execution of a program that takes multiple GB's of ram, but the only things that are stored should be ~50MB of data at most, yet mathkernel.exe tends to hold onto ~1.5GB (basically, as much as Windows will give it). Is there any better way to get around this, other than saving the data I need and quitting the kernel every time?
我刚刚了解了ByteCount函数(该函数在基本数据类型上显示了一些令人不安的结果,但这并不重要),但即使是我所有变量的总和也远不及Mathkernel占用的数量.有什么作用?
I've just learned of the ByteCount function (which shows some disturbing results on basic datatypes, but that's besides the point), but even the sum over all my variables is nowhere near the amount taken by mathkernel. What gives?
推荐答案
许多用户没有意识到的一件事是,它需要占用内存才能将所有输入和输出存储在 Out
符号,无论您是否将输出分配给变量. Out
也别名为%
,其中%
是前一个输出,%%
是倒数第二个,依此类推.%123
等效于Out[123]
.
One thing a lot of users don't realize is that it takes memory to store all your inputs and outputs in the In
and Out
symbols, regardless of whether or not you assign an output to a variable. Out
is also aliased as %
, where %
is the previous output, %%
is the second-to-last, etc. %123
is equivalent to Out[123]
.
If you don't have a habit of using %
, or only use it to a few levels deep, set $HistoryLength
to 0 or a small positive integer, to keep only the last few (or no) outputs around in Out
.
您可能还希望查看功能 MaxMemoryUsed
和 MemoryInUse
.
You might also want to look at the functions MaxMemoryUsed
and MemoryInUse
.
当然,$HistoryLength
问题可能不是您的问题,但您尚未分享您的实际评估.
如果您能够发布它,也许有人可以阐明为什么它如此占用大量内存.
Of course, the $HistoryLength
issue may or not be your problem, but you haven't shared what your actual evaluation is.
If you're able to post it, perhaps someone will be able to shed more light on why it's so memory-intensive.
这篇关于在Mathematica中分析内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!