Very strange GC behaviour

G

Geert Fannes

------_=_NextPart_001_01C5A7EA.1D7D496D
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello, can someone explain why GC fails to release "a" in the program
hereunder. When I exchange the lines "a=3DA.new" and "b=3DB.new", GC =
fails
to release b.=20

=20

PROGRAM

#create some dummy classes

class A;end

class B;end

=20

#create two variables, one for each dummy class

a=3DA.new

b=3DB.new

=20

#store the object_id's for these object to check if these are still
present

bid=3Db.object_id

aid=3Da.object_id

=20

#check which objects can still be found

ObjectSpace.each_object{|obj|puts("a still found") if
obj.object_id=3D=3Daid;puts("b still found") if obj.object_id=3D=3Dbid}

puts("")

=20

#set both objects to nil and do garbage collection

b=3Dnil

a=3Dnil

GC.start

=20

#check again which object are still present. Both a and b should be
gone, but that is not the case

ObjectSpace.each_object{|obj|puts("a still found") if
obj.object_id=3D=3Daid;puts("b still found") if obj.object_id=3D=3Dbid}

=20

=20

OUTPUT:

gfannes@ivon gruby $ ruby test.rb

b still found

a still found

=20

a still found

gfannes@ivon gruby $

=20

Greetings,

Geert


------_=_NextPart_001_01C5A7EA.1D7D496D--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top