# Extensions: Init\_extension exists, looking for Deinit\_extension

**URL:** <https://www.ruby-forum.com/t/extensions-init-extension-exists-looking-for-deinit-extension/128063>\
**Category:** Ruby\
**Created:** [February 4, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/extensions-init-extension-exists-looking-for-deinit-extension/128063 "2008-02-04T18:33:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel\_SSSSkerud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@daniel\_SSSSkerud](https://www.ruby-forum.com/u/daniel_SSSSkerud)\
**Post date:** [February 4, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/extensions-init-extension-exists-looking-for-deinit-extension/128063/1 "2008-02-04T18:33:47Z")

</div>

I am allocating a resource in Init\_extension, that is, when the .so file  
is  
loaded. I am looking for a way to deallocate this resource even though  
no  
object has been created with the extension, in other words, I cannot  
release  
the resource with the garbage collector. Is there something for this?

/D

---

<div class="post-metadata">

**Author:** ![daniel\_SSSSkerud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@daniel\_SSSSkerud](https://www.ruby-forum.com/u/daniel_SSSSkerud)\
**Post date:** [February 4, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/extensions-init-extension-exists-looking-for-deinit-extension/128063/2 "2008-02-04T20:17:16Z")

</div>

As you cannot explicitly unload a require, no there’s nothing like  
this because it’s not needed. When the ruby interpreter shuts down,  
the C runtime / OS cleans up anything opened during execution.

Jason

---

<div class="post-metadata">

**Author:** ![daniel\_SSSSkerud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@daniel\_SSSSkerud](https://www.ruby-forum.com/u/daniel_SSSSkerud)\
**Post date:** [February 4, 2008, 10:25pm UTC](https://www.ruby-forum.com/t/extensions-init-extension-exists-looking-for-deinit-extension/128063/3 "2008-02-04T22:25:18Z")

</div>

On Monday 04 February 2008 20:16:22 Jason R. wrote:

> As you cannot explicitly unload a require, no there’s nothing like  
> this because it’s not needed. When the ruby interpreter shuts down,  
> the C runtime / OS cleans up anything opened during execution.

And if you have any resources you need to clean up at ruby exit, you can  
do so  
by setting rb\_set\_end\_proc() to your cleanup func.

Jan

---

<div class="post-metadata">

**Author:** ![daniel\_SSSSkerud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@daniel\_SSSSkerud](https://www.ruby-forum.com/u/daniel_SSSSkerud)\
**Post date:** [February 7, 2008, 8:44am UTC](https://www.ruby-forum.com/t/extensions-init-extension-exists-looking-for-deinit-extension/128063/4 "2008-02-07T08:44:49Z")

</div>

On Feb 4, 2008 10:24 PM, Jan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Thank you Jan, that was _exactly_ what I was looking for. And Jason,  
that is  
not at all true. When the Ruby interpreter tears down it does call the  
“free” function for all objects created from the extension that has an  
“allocate” function. I have _global_ resources that are allocated and  
needs  
to be released because of reference counting, and which is not done  
automatically by windows. I understand that if the Ruby process _dies_  
nothing can save me, but that is not the common case (and in my case  
unfortunately requires a service-restart).

Thanks! Happy-time ;D

/D
