Victor "Zverok" Shepelev wrote:
> Hi all.
> 
> Here's a problem.
> 
> I have some object of MyClass with complex "freeing" logic, and I want to
> test this logic.
> I do:
> 
> ---------
> span = ....     #somehow created object
> 
> ObjectSpace.define_finalizer(span, proc{p "gc ok"})  #define test finalizer
> 
> span.detach     #remove object from all of my internal caches, no references
> to object should exist
> 
> span = nil      #remove the last reference to object
> 
> GC.start        #<===HERE the object must be collected and finalized

This is probably a situation where GC is being conservative. A simple 
example:

class Foo; end

foo = Foo.new
foo = nil

GC.start

p ObjectSpace.each_object(Foo) {}  # ==> 1

Probably this means that the Foo instance pointer is still visible 
somewhere in the local frame.

But that doesn't mean that there is a leak:

class Foo; end

10.times do
   Foo.new
end

GC.start

p ObjectSpace.each_object(Foo) {}  # ==> 1

In my experience, it's hard to write precise unit tests for GC behavior, 
and you end up with some fuzziness. The important property of GC is 
really the asymptotic behavior.

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407