_id2ref in finalize or how get object.var from class.finalize

Discussion in 'Ruby' started by Andrey Nikitin, Dec 15, 2007.

  1. Hi, all.

    #!/usr/bin/ruby1.8

    include ObjectSpace

    class MyClass
    attr_reader :var
    def initialize(var)
    @var = var
    puts "from initialize: #{@var}"
    define_finalizer(self, self.class.method:)finalize).to_proc)
    end

    def MyClass.finalize(object_id)
    o = _id2ref(object_id)
    puts "from finalize: #{o.var}"
    end
    end # class Storage

    o = MyClass.new("The Value!")
    exit 0

    Why lines of a code after a call of function "_id2ref(object_id)" are
    never carried out?

    How it is possible to get access to variables or methods of a object
    from a method of a class :finalize?

    --
    Andrew Nikitin
     
    Andrey Nikitin, Dec 15, 2007
    #1
    1. Advertising

  2. Hi,

    At Sun, 16 Dec 2007 03:53:49 +0900,
    Andrey Nikitin wrote in [ruby-talk:283702]:
    > def MyClass.finalize(object_id)
    > o = _id2ref(object_id)
    > puts "from finalize: #{o.var}"
    > end


    Finalizer is called after the object was disposed. So _id2ref
    raises an exception.

    > How it is possible to get access to variables or methods of a object
    > from a method of a class :finalize?


    It does not exist at that moment any more.

    --
    Nobu Nakada
     
    Nobuyoshi Nakada, Dec 16, 2007
    #2
    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. Replies:
    1
    Views:
    324
    skyofdreams
    Mar 30, 2007
  2. metaperl
    Replies:
    3
    Views:
    622
    Mark Space
    Aug 23, 2007
  3. Ara.T.Howard

    ObjectSpace::_id2ref and GC

    Ara.T.Howard, Jun 6, 2005, in forum: Ruby
    Replies:
    2
    Views:
    143
    Ara.T.Howard
    Jun 7, 2005
  4. andrey
    Replies:
    0
    Views:
    170
    andrey
    Dec 15, 2007
  5. Charles Oliver Nutter

    DRbIdConv without _id2ref

    Charles Oliver Nutter, Oct 29, 2009, in forum: Ruby
    Replies:
    0
    Views:
    104
    Charles Oliver Nutter
    Oct 29, 2009
Loading...

Share This Page