Skip to content

Instantly share code, notes, and snippets.

@gstark
Created January 21, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gstark/1ab502d134cf00441a11 to your computer and use it in GitHub Desktop.
Save gstark/1ab502d134cf00441a11 to your computer and use it in GitHub Desktop.
BIG_BEFORE="big before"
BIG_AFTER="big after"
GARBAGE="garbage"
REGEXP=/big /
$big_after_id = 0
$big_before_id = 0
$callable_id = 0
$use_proc = true
class Callable
def call
"whatever"
end
end
def thing
big_before_object = BIG_BEFORE*500_000
$big_before_id = big_before_object.object_id
if $use_proc
returned_proc = proc { |x| big_before_object }
end
big_after_object = BIG_AFTER*500_000
$big_after_id = big_after_object.object_id
if $use_proc
returned_proc
else
Callable.new
end
end
def show_gc
GC.start
ids = ObjectSpace.each_object.map(&:object_id)
puts "Before: #{ids.include?($big_before_id)}"
puts "After: #{ids.include?($big_after_id)}"
puts "Callable: #{ids.include?($callable_id)}"
end
puts "Uses proc: #{$use_proc}\n\n"
callable = thing
$callable_id = callable.object_id
show_gc
puts "\n\nZapping the callable\n\n"
callable = nil
show_gc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment