T
Thierry Lambert
Minasan konbanha
I have a question about garbage collection. In short, I thought that
releasing any reference to an object, and then calling GC.start would
garbage-collect the object. It turns out not to be true (on Windoze),
and I've been scratching my head to understand what's going on (in
vain).
Here's the problem:
class Test
end
class Inner < Test
end
class Outer < Test
def initialize
@inner = Inner.new
end
def free
@inner = nil
end
end
o = Outer.new
o.free
GC.start
# Now inner object should be gone, right? Wrong:
ObjectSpace.each_object(Test) { |o| puts o.inspect }
# => #<Inner:0x40b4470>
#<Outer:0x40b4ff8 @inner=nil>
I'm using ruby 1.8.7p249, but I have the same results with 1.9.1p378.
I'm on windoze (yeah, I know...). The problem does not appear on my Mac
(Inner is gone after GC). Any idea about this, a workaround? I need to
free OLE automation objects, that's why...
Cheers
-- Thierry
I have a question about garbage collection. In short, I thought that
releasing any reference to an object, and then calling GC.start would
garbage-collect the object. It turns out not to be true (on Windoze),
and I've been scratching my head to understand what's going on (in
vain).
Here's the problem:
class Test
end
class Inner < Test
end
class Outer < Test
def initialize
@inner = Inner.new
end
def free
@inner = nil
end
end
o = Outer.new
o.free
GC.start
# Now inner object should be gone, right? Wrong:
ObjectSpace.each_object(Test) { |o| puts o.inspect }
# => #<Inner:0x40b4470>
#<Outer:0x40b4ff8 @inner=nil>
I'm using ruby 1.8.7p249, but I have the same results with 1.9.1p378.
I'm on windoze (yeah, I know...). The problem does not appear on my Mac
(Inner is gone after GC). Any idea about this, a workaround? I need to
free OLE automation objects, that's why...
Cheers
-- Thierry