From: "Kroeger, Simon (ext)" Date: 2006-07-24T23:16:27+09:00 Subject: Re: GC in C extension.... > From: jared.r.richardson@gmail.com > 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? That's how I do it: I declare a global Hash (just because it's faster than an array) like $__keep_me__ = {} (easiest way is to use eval to do that from c) in this hash I put all the stuff my c part allocates and I want to keep for later. (objects that are referenced from global containers do not get GC'ed). If I don't need these objects anymore I remove them from the hash (and the GC will wipe them away sometime) So put your result set in such a container when you create it and remove it if you handle it down to your user. cheers Simon