Created
January 21, 2015 13:59
-
-
Save gstark/1ab502d134cf00441a11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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