Over a million developers have joined DZone.

Basic Memory Profiling

·
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:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}