From: William Djaja Tjokroaminata Date: 2002-10-24T23:43:17+09:00 Subject: Re: On Using Data_Wrap_Struct Tim Hunter wrote: > As long as you need the array, (which I assume is as long as the Foo > object is alive) you must mark its VALUE whenever gc calls Foo's mark > function. Otherwise gc will delete it out from under you. The array, > in turn, will take care of marking the VALUEs it contains, including > the n and msg VALUEs you push on it. > When you create a Foo object with Data_Wrap_Struct or > Data_Make_Struct, include a pointer to a "mark function". GC will call > the mark function periodically, during the "mark" part of its mark & > sweep. It's the mark function's responsibility to mark any VALUEs > contained in the Foo object so that gc can tell that they're still > alive. Just add a call to rb_gc_mark(my_ary) in the mark function. Mmmm... actually if the array is an instance variable, as Mark wrote ...Foo has an array member called @arr... then we don't need to explicitly mark it, as Ruby already does it for us. Regards, Bill