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:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}