Extensions: Init_extension exists, looking for Deinit_extension

D

daniel åkerud

[Note: parts of this message were removed to make it a legal post.]

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
 
J

Jason Roelofs

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
 
J

Jan Dvorak

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
 
D

daniel åkerud

[Note: parts of this message were removed to make it a legal post.]

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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,283
Messages
2,571,405
Members
48,098
Latest member
inno vation

Latest Threads

Top