From: billtj@... (Bill Tj) Date: 2002-08-13T01:28:01+09:00 Subject: Re: Are All C Destructors Guaranteed to Be Called? Hi, Yes, after performing repetitive test (i.e., creating the objects and "resetting" them many-many times), I could see some memory leaks. After the leaks were fixed, then when I tried the simple test case, I could see that all the object "free" functions were indeed called. Thanks for your assertion. Now I conclude that if a C extension is implemented correctly, all the object free functions should be called before Ruby exits. Regards, Bill ============================================================================= Paul Brannan wrote in message news:<20020809123333.M11837@atdesk.com>... > On Fri, Aug 09, 2002 at 11:24:27PM +0900, William Djaja Tjokroaminata wrote: > > Are all C destructors, i.e., the "free" function that is specified in > > Data_Make_Struct (VALUE, c-type, mark, "free", c-type*), guaranteed to be > > called when the Ruby script/process exits? > > They get called when the object needs to be destroyed. I think all > objects are supposed to be destroyed at exit. > > > I put "printf" on all the "free" functions, and one of them did not get > > called. Is it a sign that something is still not clean? How about > > circular reference (I think I have one in my code)? Will circular > > reference cause the free function not called at the end of the > > script/process? > > 1) Can you reproduce this behavior in a small test case? > 2) Ruby uses mark/sweep instead of reference counting, so circular > references won't cause an object to not get GC'd. What *can* happen > is that an object doesn't get destroyed because someone is keeping a > reference who is not supposed to be keeping a reference, but both > objects should be destroyed at exit. > > Paul