Very strange GC behaviour

Discussion in 'Ruby' started by Geert Fannes, Aug 23, 2005.

  1. Geert Fannes

    Geert Fannes Guest

    ------_=_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--
    Geert Fannes, Aug 23, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    470
    Raymond Hettinger
    Jul 27, 2003
  2. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,615
    Merrill & Michele
    Oct 19, 2004
  3. Abhishek Jha

    very very very long integer

    Abhishek Jha, Oct 16, 2004, in forum: C Programming
    Replies:
    4
    Views:
    418
    jacob navia
    Oct 17, 2004
  4. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    512
    Dave Thompson
    Feb 14, 2005
  5. Sunjay Varma
    Replies:
    4
    Views:
    342
    John Roth
    Mar 10, 2011
Loading...

Share This Page