It doesn't produce any output!

Hi,
I wonder if something is wrong with the following code.
Because, it doesn’t produce any output.
BTW, I am new to Ruby.

Regards
yc

include ObjectSpace

a=b=c=“A”

define_finalizer(a, proc {|id| puts “Finalizer
#{ObjectSpace._id2ref(id)} on #{id}” })
define_finalizer(b, proc {|id| puts “Finalizer
#{ObjectSpace._id2ref(id)} on #{id}” })
define_finalizer(c, proc {|id| puts “Finalizer
#{ObjectSpace._id2ref(id)} on #{id}” })

On 02.05.2007 16:50, Yusuf C. wrote:

a=b=c=“A”

define_finalizer(a, proc {|id| puts “Finalizer
#{ObjectSpace._id2ref(id)} on #{id}” })
define_finalizer(b, proc {|id| puts “Finalizer
#{ObjectSpace._id2ref(id)} on #{id}” })
define_finalizer(c, proc {|id| puts “Finalizer
#{ObjectSpace._id2ref(id)} on #{id}” })

Your finalizers lock the object in memory. You can find a recent
discussion about the topic in the archives.

Please note also that you are defining three finalizers for a single
instance which is probably not what you want.

Kind regards

robert

Thanks Robert,

But, without #{ObjectSpace._id2ref(id)} no problem.
You think this statement locks the object in memory.

Thanks again
yc

Robert K. wrote:

Your finalizers lock the object in memory. You can find a recent
discussion about the topic in the archives.

Please note also that you are defining three finalizers for a single
instance which is probably not what you want.

Kind regards

robert

On 03.05.2007 09:18, Yusuf C. wrote:

Thanks Robert,

But, without #{ObjectSpace._id2ref(id)} no problem.
You think this statement locks the object in memory.

No, that’s not the one. The mere fact that you define a proc / lambda
in the presence of a local variable that references the object is
keeping the object around. The proc is a closure and keeps a reference
to a even if a goes out of scope (which it does not in your case).

robert

On 5/3/07, Yusuf C. [email protected] wrote:

discussion about the topic in the archives.
Posted via http://www.ruby-forum.com/.

it is pretty well documented that you cannot do that. From the docs
of ObjectSpace._id2ref:

Converts an object id to a reference to the object. May not be
called on an object id passed as a parameter to a finalizer.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs