From: Nobuyoshi Nakada Date: 2002-04-19T09:54:09+09:00 Subject: Re: GC problem in C++ extension Hi, At Fri, 19 Apr 2002 08:53:55 +0900, Paul Brannan wrote: > > and, in fact, I do see that if I delete line 25. How can I make sure > > that the allocated Foo object gets properly destructed? It's not predictable when an object will be gargage-collected. > Ouch, I should proofread before I post. The correct change to make to > get the behavior I want is not to delete line 25, but to change: > > VALUE v = Data_Wrap_Struct(rb_cObject, 0, (RUBY_DATA_FUNC)Foo::free, f); > > to: > > Data_Wrap_Struct(rb_cObject, 0, (RUBY_DATA_FUNC)Foo::free, f); > > Why does making this change allow the object to get garbage collected? In former case, the new object might be stored in the stack, and marked there. Just my guess. -- Nobu Nakada