Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Basic Memory Profiling

DZone's Guide to

Basic Memory Profiling

·
Free Resource
Simple memory usage by class dump using ObjectSpace.


s = Hash.new(0);
ObjectSpace.each_object do |o|
  s[o.class] += Marshal.dump(o).size rescue 0
end

w = s.keys.map{|v|v.to_s.length}.max
puts s.to_a.sort{|a,b|b[1]<=>a[1]}.map{|k,v|"%#{w}s %d"%[k,v]}.join("\n")
puts "#{' ' * w} #{s.to_a.inject(0){|n,a| n += a[1]}}"
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}