Is there a package to list memory consumption of selected data objects?

Super neat, I didn’t know about that macro! I’m totally going to add a macro like this into my startup.jl file:

macro show_locals()
  quote 
    locals = Base.@locals
    println("\nIndividual sizes (does not account for overlap):")
    for (name, refval) in locals
      println("\t$name: $(Base.format_bytes(Base.summarysize(refval)))")
    end
    print("Joint size: ")
    println("$(Base.format_bytes(Base.summarysize(values(locals))))\n")
  end
end

# example use:
function tester(n)
  x = randn(n,n)
  @show_locals
  sum(x)
end

With example output:

julia> tester(100)

Individual sizes (does not account for overlap):
	n: 8 bytes
	x: 78.164 KiB
Joint size: 78.625 KiB

94.23373017998107

I love threads like this where I learn some nifty trick. I was just wishing a month or two ago to do something like this but I didn’t really take the initiative do something about it and try to figure out a solution.

9 Likes