# It doesn't produce any output!

**URL:** <https://www.ruby-forum.com/t/it-doesnt-produce-any-output/103164>\
**Category:** Ruby\
**Created:** [May 2, 2007, 4:50pm UTC](https://www.ruby-forum.com/t/it-doesnt-produce-any-output/103164 "2007-05-02T16:50:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yusufcelik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ba9def/32.png) [@yusufcelik](https://www.ruby-forum.com/u/yusufcelik)\
**Post date:** [May 2, 2007, 4:50pm UTC](https://www.ruby-forum.com/t/it-doesnt-produce-any-output/103164/1 "2007-05-02T16:50:09Z")

</div>

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}” })

---

<div class="post-metadata">

**Author:** ![yusufcelik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ba9def/32.png) [@yusufcelik](https://www.ruby-forum.com/u/yusufcelik)\
**Post date:** [May 2, 2007, 5:01pm UTC](https://www.ruby-forum.com/t/it-doesnt-produce-any-output/103164/2 "2007-05-02T17:01:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yusufcelik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ba9def/32.png) [@yusufcelik](https://www.ruby-forum.com/u/yusufcelik)\
**Post date:** [May 3, 2007, 9:18am UTC](https://www.ruby-forum.com/t/it-doesnt-produce-any-output/103164/3 "2007-05-03T09:18:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yusufcelik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ba9def/32.png) [@yusufcelik](https://www.ruby-forum.com/u/yusufcelik)\
**Post date:** [May 3, 2007, 11:01am UTC](https://www.ruby-forum.com/t/it-doesnt-produce-any-output/103164/4 "2007-05-03T11:01:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yusufcelik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ba9def/32.png) [@yusufcelik](https://www.ruby-forum.com/u/yusufcelik)\
**Post date:** [May 3, 2007, 2:02pm UTC](https://www.ruby-forum.com/t/it-doesnt-produce-any-output/103164/5 "2007-05-03T14:02:07Z")

</div>

On 5/3/07, Yusuf C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > discussion about the topic in the archives.  
> > Posted via [http://www.ruby-forum.com/](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.
