1
$\begingroup$

Given the list of stored variables

Names@"`*"

is it possible to sort them by size in used memory?

$\endgroup$
3
  • $\begingroup$ I used this in the past : checkMemory[] := Module[{u}, u = MemoryInUse[]*100/(MemoryInUse[] + MemoryAvailable[]) // N; Print["memory used= " <> ToString[u] <> "%"]; Grid[Reverse@ SortBy[({ByteCount[ToExpression[#1]]*100/MemoryAvailable[] // N, HoldForm[#1]} &) /@ Names["Global*"], First]] ]` $\endgroup$ Dec 13, 2022 at 4:21
  • 1
    $\begingroup$ Here's a rough attempt to sort by the size of the OwnValues, i.e. to differentiate true "variable" symbols not symbols that auto evaluate: SortBy[Names["`*"], ToExpression[#, StandardForm, Function[Null, ByteCount[HoldComplete[#] /. OwnValues[#]], HoldAllComplete]] $\endgroup$
    – b3m2a1
    Dec 13, 2022 at 4:31
  • 1
    $\begingroup$ SortBy[Names@"`*", ByteCount@ToExpression@# &] $\endgroup$
    – Bob Hanlon
    Dec 13, 2022 at 5:16

0

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.

Browse other questions tagged or ask your own question.