Memory Issues with C extensions and each blocks

Z

Zed A. Shaw

Hi,

While writing the Ruby/Odeum C extension I ran into this problem where
object allocated inside an each block did not get collected until the
each block exited.

At first I thought it was because I had implemented the each block in C
and I wasn't doing something right. But then I got rid of the C each
block and used a Ruby each in the test scripts and saw the same problem.
Objects will get allocated from the C extension, build up during the
each execution, and then at the end they get properly collected. I
verified this by having the registered free functions print a message to
stdout.

My current solution is to have an explicity "close" method on the one
object that offends the most and warn the users, but I'm wondering if
there's some C extension magic that I'm misssing.

Any help is greatly appreciated.

Zed A. Shaw
http://www.zedshaw.com/
 
T

Tilman Sauerbeck

Zed A. Shaw said:
My current solution is to have an explicity "close" method on the one
object that offends the most and warn the users, but I'm wondering if
there's some C extension magic that I'm misssing.

You're probably not missing anything - your code shouldn't break if the
GC isn't called in specific intervals or at a specific time, since stuff
like this isn't defined.

So, using a "close" method seems to be the best way to handle this.

I don't know of any "extension magic" regarding your problem either.
 

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
473,792
Messages
2,569,639
Members
45,349
Latest member
RebbecaHen

Latest Threads

Top