From: "jared.r.richardson@..." Date: 2006-07-24T22:20:05+09:00 Subject: Re: GC in C extension.... Stephen Kellett wrote: > In message <1153489176.647779.292870@s13g2000cwa.googlegroups.com>, > "jared.r.richardson@gmail.com" writes > >I think I've solved this... I assumed because the upper level arrays > >were global that the contents would be safe. This was apparently not > >the case. I added this line to protect the result set array > > > >rb_global_variable(&resultset); > > > >And it stopped corrupting. I think this call declares the variable to > >the garbage collector so that it's aware not to clean up the contents. > > I was going to answer this, but it seems you've got there before I could > answer. Putting your VALUEs into C global arrays does not automatically > make them visible to the Ruby GC, you do need to take some action (as > you have done) to make the Ruby GC aware of them to avoid unwanted > collection before you need them collected. > 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? Thanks, Jared http://jaredrichardson.net > Stephen > -- > Stephen Kellett > Object Media Limited http://www.objmedia.demon.co.uk/software.html > Computer Consultancy, Software Development > Windows C++, Java, Assembler, Performance Analysis, Troubleshooting