7
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Somewhat related: (9634), $\endgroup$
    – Mr.Wizard
    Jan 5, 2015 at 15:10

1 Answer 1

7
$\begingroup$

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.

$\endgroup$
11
  • $\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$
    – MOON
    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$
    – Rom38
    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$
    – MOON
    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$
    – Rom38
    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å
    Jan 5, 2015 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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