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}" })
···
--
Posted via http://www.ruby-forum.com/.
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 02.05.2007 16:50, Yusuf Celik wrote:
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}" })
Thanks Robert,
But, without #{ObjectSpace._id2ref(id)} no problem.
You think this statement locks the object in memory.
Thanks again
yc
Robert Klemme 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
--
Posted via http://www.ruby-forum.com/\.
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 03.05.2007 09:18, Yusuf Celik wrote:
Thanks Robert,
But, without #{ObjectSpace._id2ref(id)} no problem.
You think this statement locks the object in memory.
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.
···
On 5/3/07, Yusuf Celik <ycelik@oytek.com.tr> wrote:
Thanks Robert,
But, without #{ObjectSpace._id2ref(id)} no problem.
You think this statement locks the object in memory.
Thanks again
yc
Robert Klemme 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
--
Posted via http://www.ruby-forum.com/\.
--
Chris Carter
concentrationstudios.com
brynmawrcs.com