On Sep 25, 2007, at 10:14 AM, Sylvain Joyeux wrote:

>> it seems like you should be able to define a finalizer on any object
>> without preventing it from being gc'd!
> The only way I am aware of is to use methods ...
> ObjectSpace.define_finalizer(obj, &method(:my_finalizer))
> --  
> Sylvain Joyeux                              http://www.laas.fr/ 
> ~sjoyeux

yeah - trying to prevent the closure... smart.  i'm not having luck  
though:

cfp:~ > cat a.rb
class C
   def self.count
     c = 0
     ObjectSpace.each_object do |object|
       c += 1 if self === object rescue next
     end
     c
   end
end

def nothing
end

loop do
   #c = nil  ### try with and without this!!!!!!!!!!!!!!

   (2 ** 16).times do
     c = C.new
     ObjectSpace.define_finalizer c, &method(:nothing)
   end

   puts "before: #{ C.count }"

   GC.start

   puts "after: #{ C.count }"
   puts
end


again, if you un-comment the 'c = nil' line it'll work, but avoid the  
closure alone doesn't work on my platform.  does it work for you?   
did i misunderstand your comment perhaps?

thanks alot for the input.

kind regards.

a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama