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$ Commented 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
    Commented Dec 13, 2022 at 4:31
  • 2
    $\begingroup$ SortBy[Names@"`*", ByteCount@ToExpression@# &] $\endgroup$
    – Bob Hanlon
    Commented Dec 13, 2022 at 5:16

0

Your Answer

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

Browse other questions tagged or ask your own question.