Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Created February 7, 2012 12:12
Show Gist options
  • Save bil-bas/1759408 to your computer and use it in GitHub Desktop.
Save bil-bas/1759408 to your computer and use it in GitHub Desktop.
Count objects
module GC
def self.count_objects_by_class
@@runs ||= []
run = Hash.new 0
@@runs << run
# Count objects of each class.
ObjectSpace.each_object do |obj|
run[obj.class.name.to_sym] += 1
end
# List classes and number of them in each run.
@@runs.map(&:keys).flatten.uniq.sort.each do |klass|
puts "#{klass} #{@@runs.map {|r| r[klass] }}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment