From: Tim Hunter Date: 2008-09-20T02:00:55+09:00 Subject: Re: IRB + C Extension = Memory Loss Ryan Bates wrote: > I'm having difficult making a simple C extension. The struct's memory > seems to go missing after a while when using IRB. I'm no C expert, so > I'm probably doing something wrong as far as memory allocation is > concerned. Here's the problem and the code: > > http://gist.github.com/11611 > > Notice the greeting goes away after calling "h.greet" a number of > times? This only seems to happen in IRB and not through a ruby script. > Any idea why? I'm assuming it has something to do with Ruby's garbage > collection, but I don't know how to solve it. > > Thanks, > > Ryan GC is collecting the greeting string because it thinks there are no references to it. Your hello_mark function needs to identify the greeting string object as "in use". From the Pickaxe: "The mark routine will be called by the garbage collector during its ``mark'' phase. If your structure references other Ruby objects, then your mark function needs to identify these objects using rb_gc_mark(value)." -- Posted via http://www.ruby-forum.com/.