Skip to content

Instantly share code, notes, and snippets.

@hanshasselberg
Last active December 11, 2015 03:58
Show Gist options
  • Save hanshasselberg/4541852 to your computer and use it in GitHub Desktop.
Save hanshasselberg/4541852 to your computer and use it in GitHub Desktop.
$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
$ irb --version
irb 0.9.6(09/06/30)
$ irb
> a = "gc me"
=> "gc me"
> ObjectSpace.define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
=> [0, #<Proc:0x007f9e2abb9200@(irb):3>]
> a = nil
> GC.start
=> nil
> ObjectSpace.garbage_collect
=> nil
> exit
Finalizer one on 70158648666720
@hanshasselberg
Copy link
Author

What's going on?

I expect that either GC.start or ObjectSpace.garbage_collect is calling the finalizer - but thats happening only when I close the session.

WHY?

@coffeejunk
Copy link

$ ruby --version
ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-darwin12.2.1]
$ irb --version 
irb 0.9.6(09/06/30)
$ irb 
> a = "gc me"
 => "gc me" 
> ObjectSpace.define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
 => [0, #<Proc:0x007fcfa188e410@(irb):2>] 
> a = nil
 => nil 
> GC.start
Finalizer one on 70264872626760
 => nil 
> ObjectSpace.garbage_collect
 => nil 
> ^D

@hanshasselberg
Copy link
Author

@coffeejunk Thanks! I'm going to upgrade then!

@hanshasselberg
Copy link
Author

@coffeejunk It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment