From: Wim van den Bos Date: 2005-03-29T03:02:46+09:00 Subject: Is there something wrong with the GC? ------=_NextPart_000_002C_01C533D1.72009770 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I tried the following script: #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D class Example end a=3DExample.new ObjectSpace.each_object(Example) { |e| print e,"\n" } a=3Dnil GC.enable GC.start ObjectSpace.each_object(Example) { |e| print e,"\n" } #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Output: # # The Example object is still active after the GC.start, I expected it to = be gone. :-( So I tried the WeakRef, and this also did something strange. I wrote the 'Programming Ruby' book example: #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D require "weakref" ref =3D "fol de rol" puts "Initial object is #{ref}" ref =3D WeakRef.new(ref) puts "Weak reference is #{ref}" ObjectSpace.garbage_collect begin puts "But then it is #{ref}" rescue Exception=3D>e puts e end #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Output: Initial object is fol de rol Weak reference is fol de rol Illegal Reference - probably recycled And this worked ok.=20 I then copied the whole and just defined a class in between: #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D require "weakref" ref =3D "fol de rol" puts "Initial object is #{ref}" ref =3D WeakRef.new(ref) puts "Weak reference is #{ref}" ObjectSpace.garbage_collect begin puts "But then it is #{ref}" rescue Exception=3D>e puts e end # # doing it for the second time, and created a class definition # and now it doesn't work # class Example end # ref =3D "fol de rol" puts "Initial object is #{ref}" ref =3D WeakRef.new(ref) puts "Weak reference is #{ref}" ObjectSpace.garbage_collect begin puts "But then it is #{ref}" rescue Exception=3D>e puts e end #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Output: Initial object is fol de rol Weak reference is fol de rol Illegal Reference - probably recycled Initial object is fol de rol Weak reference is fol de rol But then it is fol de rol And this is strange the second 'ref' is not collected. If the class = definition is removed all works well. I tested this in the mswin32 version. 1.8.2 and in the older version = 1.6.8 both with the same results. The cygwin version 1.8.2 had the same results also. To be sure I the downloaded 1.9.0 and this also went wrong. It looks like the Garbage Collector is not working properly. Can anybody = help. Thanks. Wim... ------=_NextPart_000_002C_01C533D1.72009770--