Skip to content

Instantly share code, notes, and snippets.

@vipulnsward
Created September 28, 2013 20:46
Show Gist options
  • Save vipulnsward/6746362 to your computer and use it in GitHub Desktop.
Save vipulnsward/6746362 to your computer and use it in GitHub Desktop.
# Object Counter for use in example on vipulnsward.com about Frozen
# Strings in Ruby
module ObjectCounter
def self.count
GC.disable
before_count = ObjectSpace.count_objects
yield
after_count = ObjectSpace.count_objects
after_count.each do |k,v|
after_count[k] = v.to_i - before_count[k].to_i
end
GC.enable
after_count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment