jared.r.richardson@gmail.com
7/24/2006 1:59:00 PM
Kroeger, Simon (ext) wrote:
> > From: jared.r.richardson@gmail.com
> > [mailto:jared.r.richardson@gmail.com]
> > Sent: Monday, July 24, 2006 3:20 PM
>
> >
> > Here's a follow-on then.. my program is now running great but leaking
> > lots of memory. :) Because it's a database driver, it doesn't
> > terminate
> > but rather runs for a very long time.
> >
> > Declaring the variable as rb_global_variable prevents Ruby
> > from garbage
> > collecting it. How do I release it back to Ruby again? Is there a
> > rb_unset_global_variable?
>
> Not that I know of, but use a global array or hash and put everything
> you want to keep in it. Inserting and deleting from a hash should
> be even faster than rb_global_variable.
>
> cheers
>
> Simon
Hi Simon,
In my C code I have a VALUE result_set that I set = ary_ary_new with
each call to the database. I put new VALUE objects in this result set.
After a bit, howevever, the VALUE objects I'm putting into the result
set become invalid. It appears that GC was reaping them.
Now that I've declared the result_set as an rb_global_variable, the bad
reaping has stopped... but now the memory is leaking. I assume it's
from the orphaned variables from the last loop.
That make more sense?