Hi,
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?
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?
I know that in Python circular reference can cause trouble since it gc
uses reference counting. But Ruby gc uses mark-and-sweep method.
Regards,
Bill
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?
- Can you reproduce this behavior in a small test case?
- 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
···
On Fri, Aug 09, 2002 at 11:24:27PM +0900, William Djaja Tjokroaminata wrote:
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 pbrannan@atdesk.com 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?
- Can you reproduce this behavior in a small test case?
- 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