Skip to content

Instantly share code, notes, and snippets.

@jballanc
Created December 21, 2011 17:54
Show Gist options
  • Save jballanc/1506977 to your computer and use it in GitHub Desktop.
Save jballanc/1506977 to your computer and use it in GitHub Desktop.
Count Objects across GC's
$h = {}
$s = ""
$f = proc do
ObjectSpace.count_objects($h)
$c += $h[:TOTAL] - $h[:FREE]
$s = ""
ObjectSpace.define_finalizer($s, $f)
$s = nil
puts "Total objects allocated: #{$c}, GC Cycles: #{GC.count}"
end
ObjectSpace.define_finalizer($s, $f)
$c = 0
$s = nil
GC.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment