http://www.rubygarden.org/ruby?GCAndExtensions
I did. It was useful as far as it went. What it didânt say was how the
object created with Data_Wrap_Struct could be registered with the GC.
Thanks for the critique. I donât want to look it up in âProgramming Rubyâ
right now, but basically, Data_Wrap_Struct takes two functions as
argument (besides the Struct in question), and creates a new ruby object.
The new ruby object is automatically known to the Garbage collector. You
donât have to do anything else to âregisterâ it.
But you can register two functions for your new object that will be called
from the garbage collector. This reqistration is part of
Data_Wrap_Structâs action. Pass pointers to these functions as arguments
of the Data_Wrap_Struct macro.
These two function arguments take function pointers to be called during
the mark phase and the sweep phase of the GC, respectively. The latter
will only be called if the object is finally deleted.
Neither did it mention how the interpreter marks the current stack
frame when ruby_init()
Iâm no expert here, but I donât think it marks the current stack frame,
because there is no need to do this. The GC can simply scan the whole C
stack for pointers to ruby objects.
is called thus enabling c side ruby objects to
be automatically marked by the GC.
If there are pointers to these Objects on the stack (variables of type
VALUE), then they will automatically be marked every time the GC enters a
mark phase.
Knowing this then raises the
question of how to tell the GC that, if the previously created object
is retained (struct,heap etc), it should not be reaped
I donât understand this.
Finally, it does not explain how to release a retained object when
youâre done.
A ruby object is deleted after a GC mark phase, iff it did not recieve a
mark during that particular mark phase. You can not explicitly delete an
object. Thatâs the GCâs responsibility.
Tobias
¡¡¡
On 13 Apr 2003, Steve Hart wrote: