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

**URL:** <https://discourse.julialang.org/t/is-there-a-package-to-list-memory-consumption-of-selected-data-objects/85019>\
**Category:** General Usage\
**Tags:** memory\
**Created:** [July 30, 2022, 2:54am UTC](https://discourse.julialang.org/t/is-there-a-package-to-list-memory-consumption-of-selected-data-objects/85019 "2022-07-30T02:54:30Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![cgeoga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgeoga/32/216186_2.png) [@cgeoga](https://discourse.julialang.org/u/cgeoga)\
**Post date:** [July 31, 2022, 5:23pm UTC](https://discourse.julialang.org/t/is-there-a-package-to-list-memory-consumption-of-selected-data-objects/85019/12 "2022-07-31T17:23:35Z")

</div>

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

```julia
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
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.

---

_[View the full topic](https://discourse.julialang.org/t/is-there-a-package-to-list-memory-consumption-of-selected-data-objects/85019)._
