From: ts Date: 2005-04-13T02:00:38+09:00 Subject: Re: ability to run finalizers at a given point of a program? >>>>> "G" == Guillaume Cottenceau writes: G> http://www.zarb.org/~gc/t/prog/destructor/nodestructor.rb The code is G> class Foo G> def initialize G> puts "*** constructor" G> end G> end G> G> G> def scopeme G> foo = Foo.new G> ObjectSpace.define_finalizer(foo, proc { puts "*** pseudo-destructor" }) G> end G> G> scopeme G> puts "Foo was out-scoped." G> G> GC.start G> puts "Gc was run." you must know that the gc is a little special, try it with svg% cat b.rb #!/usr/local/bin/ruby class Foo def initialize puts "*** constructor" end def self.final proc { puts "*** pseudo-destructor" } end end def scopeme foo = Foo.new ObjectSpace.define_finalizer(foo, Foo.final) end a = scopeme puts "Foo was out-scoped." GC.start puts "Gc was run." svg% svg% b.rb *** constructor Foo was out-scoped. *** pseudo-destructor Gc was run. svg% Guy Decoux