# Writing a destructor is possible?

**URL:** <https://www.ruby-forum.com/t/writing-a-destructor-is-possible/87242>\
**Category:** Ruby\
**Created:** [March 1, 2007, 3:00am UTC](https://www.ruby-forum.com/t/writing-a-destructor-is-possible/87242 "2007-03-01T03:00:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume\_Nargeot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@Guillaume\_Nargeot](https://www.ruby-forum.com/u/Guillaume_Nargeot)\
**Post date:** [March 1, 2007, 3:00am UTC](https://www.ruby-forum.com/t/writing-a-destructor-is-possible/87242/1 "2007-03-01T03:00:57Z")

</div>

I would like to know if it is possible to write (for a class) something  
like  
a destructor (like you do with C++), or something equivalent.  
If it is not possible, how can I do to perform some operations on the  
deletion of my object ?

---

<div class="post-metadata">

**Author:** ![Guillaume\_Nargeot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@Guillaume\_Nargeot](https://www.ruby-forum.com/u/Guillaume_Nargeot)\
**Post date:** [March 1, 2007, 3:45am UTC](https://www.ruby-forum.com/t/writing-a-destructor-is-possible/87242/2 "2007-03-01T03:45:03Z")

</div>

On 2/28/07, Guillaume Nargeot  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I would like to know if it is possible to write (for a class) something like  
> a destructor (like you do with C++), or something equivalent.  
> If it is not possible, how can I do to perform some operations on the  
> deletion of my object ?

Please look in the archives; this was just discussed last week.

In short, you can write a finalizer, but you’ll never use it because  
it may not be called. If you must release resources when your object  
is destroyed, ensure that you provide a block form (like File.open).

-austin

---

<div class="post-metadata">

**Author:** ![Guillaume\_Nargeot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@Guillaume\_Nargeot](https://www.ruby-forum.com/u/Guillaume_Nargeot)\
**Post date:** [March 1, 2007, 7:13am UTC](https://www.ruby-forum.com/t/writing-a-destructor-is-possible/87242/3 "2007-03-01T07:13:20Z")

</div>

> Please look in the archives; this was just discussed last week.
> 
> In short, you can write a finalizer, but you’ll never use it because  
> it may not be called. If you must release resources when your object  
> is destroyed, ensure that you provide a block form (like File.open).
> 
> -austin

Sorry, but I don’t know were to find these archives… I thought I found  
them on the internet, but I didn’t find anything into them by searching  
for “destructor” or “finalizer”. Even by filtering this newsgroup topics  
with these words I can’t find anything since the 2007-02-16.

Can you tell me where I can find this discussion please ?

---

<div class="post-metadata">

**Author:** ![Guillaume\_Nargeot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@Guillaume\_Nargeot](https://www.ruby-forum.com/u/Guillaume_Nargeot)\
**Post date:** [March 1, 2007, 9:16am UTC](https://www.ruby-forum.com/t/writing-a-destructor-is-possible/87242/4 "2007-03-01T09:16:36Z")

</div>

On Feb 28, 2007, at 22:11, Guillaume Nargeot wrote:

> them on the internet, but I didn’t find anything into them by  
> searching  
> for “destructor” or “finalizer”. Even by filtering this newsgroup  
> topics  
> with these words I can’t find anything since the 2007-02-16.
> 
> Can you tell me where I can find this discussion please ?

[http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml](http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml)

(google “ruby-talk archives”)

---

<div class="post-metadata">

**Author:** ![Guillaume\_Nargeot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@Guillaume\_Nargeot](https://www.ruby-forum.com/u/Guillaume_Nargeot)\
**Post date:** [March 1, 2007, 9:50am UTC](https://www.ruby-forum.com/t/writing-a-destructor-is-possible/87242/5 "2007-03-01T09:50:39Z")

</div>

Guillaume Nargeot wrote:

> for “destructor” or “finalizer”. Even by filtering this newsgroup topics  
> with these words I can’t find anything since the 2007-02-16.
> 
> Can you tell me where I can find this discussion please ?  
> With google,

ObjectSpace.define\_finalize
