From: ts Date: 2004-06-06T17:44:44+09:00 Subject: Re: Problems with Ruby GC'ing a variable I'm using. >>>>> "A" == Austin McDonald writes: A> In this code snippet, p->popArray is the one getting GC'd. My mark A> function only does this: Your mark function is wrong, you must write it A> void pop_mark(VALUE self) { A> Population* p; A> Data_Get_Struct(self, Population, p); A> rb_gc_mark(p->popArray); A> } void pop_mark(Population *) { rb_gc_mark(p->popArray); } A> VALUE A> pop_new(VALUE class, VALUE size, VALUE tagsize, VALUE strategysize) { it's best if you use the scheme allocate/initialize rather than new A> Population* p = ALLOC(Population); A> /* do some stuff to the struct*/ A> VALUE obj = Data_Wrap_Struct(class, pop_mark, free, p); best to use Data_Make_Struct obj = Data_Make_Struct(class, Population, pop_mark, free, p); the advantage is that p will be filled with zero, it's important for the GC (try to avoid the variable name `class') A> VALUE argv[3]; Guy Decoux