GC.start
allocated_before = GC.stat(:total_allocated_objects) #=> ex: 108391
# ..何らかの処理..
allocated_after = GC.stat(:total_allocated_objects) #=> ex: 108871
puts "Object count: #{allocated_after - allocated_before}"
Ref. https://gist.github.com/apauly/3f547f06e83b66e4187e48519b426464