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

A

Andrey Nikitin

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?
 
N

Nobuyoshi Nakada

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.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top