Is it possible to know what percentage of total used RAM by MMA is used by individual variables? I want to know how the total used RAM is distributed among different variables. Bytecount
gives the answer but I have to enter the name of each variable manually.
$\begingroup$
$\endgroup$
1
-
$\begingroup$ Somewhat related: (9634), $\endgroup$– Mr.WizardCommented Jan 5, 2015 at 15:10
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
11
I guess you need something like this:
a = RandomReal[{0, 1}, {1000, 1000}];
b = RandomReal[{0, 1}, {10000, 10000}];
Column@Thread@{Names["Global`*"], ByteCount[#] & /@ ToExpression /@ Names["Global`*"]}
{"a", 8000152} {"b", 800000152}
It will show you all user-defined expressions and some of components of Global
context created by default.
-
$\begingroup$ I use MMA 9. Executing the code returns nothing. I think this is because I set the notebook's context as
Unique to this notebook
$\endgroup$– MOONCommented Jan 5, 2015 at 12:55 -
$\begingroup$ I've checked this namelly with MMA9. Did you run it on an empty kernel? Try to create any expression before.. $\endgroup$– Rom38Commented Jan 5, 2015 at 12:57
-
$\begingroup$ It works if the notebook's context is set to Global. If the context is unique to the notebook it won't work. $\endgroup$– MOONCommented Jan 5, 2015 at 12:59
-
1$\begingroup$ Yes, :) because the list of variables is taken from the Global context. You can replace the name of context to your current. Or use this
Names[$Context<>"*"]
as recommend Alexey Popkov in stackoverflow.com/questions/6166027/… $\endgroup$– Rom38Commented Jan 5, 2015 at 13:03 -
1$\begingroup$ @yashar I guess the frontend takes memory too, plus many other services. See
MemoryInUse[$FrontEnd]
$\endgroup$– ÖskåCommented Jan 5, 2015 at 13:37