This is a cryptographically signed message in MIME format.

--------------ms040300060604010901010107
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Brent,
> I went back and read this thread completely.
> Then, I had a look at the gc.c in my patched ruby 1.6.8
> (fear not, the GC hasn't changed much over the years :-)

Ah, thanks for digging in so deeply.
> 
> There certainly is no attempt to respect data dependencies 
> during the final cleanup before exit.  rb_gc_call_finalizer_at_exit()
> ends with a loop that simply frees (and finalizes) every object on
> all heaps.   I believe this explains Nobu's comment that free functions
> may not reference other objects.

Right, makes sense.


> After looking this over, I tend to agree with Nobu's later comment that
> reference counting may be useful here.  XML::Node::Set object might:
> 
>  1. increment a reference count in the parent XML document object, and 
>  2. have each document object include a flag that indicated that Ruby's GC
> had
>      attempted to free it while its reference count was non-zero.
> 
> In this case:
>  3. The XML::Node::Set's dfree would decriment the document's refcount, and
>  4. only if it reached zero and the document object's dfree had already been
> called,
>      would it would also free the document object.

What happens though when Document#free gets called first?  Then there is 
no way to avoid a segmentation fault, except not releasing the Node's Co 
object (which I guess is ok since the process is shutting down, but 
hardly good programming form).

The only solution I see is for XML::Node::Set alloc to register a 
pointer with its Document object.  When the Document object is freed, it 
would iterate over its XML::Node::Set pointers telling them to free 
their underlying C objects and setting their pointers to the Document to 
null (thus the Ruby Node::Set object will still exist so the GC still 
can call its free function, which it would be about to do).

Alternatively, if the XML::Node::Set is freed first it would unregister 
itself with its document.

That should work, but its seems like this should be general issue with a 
general solution (ala mark/sweep).

Charlie

--------------ms040300060604010901010107
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIJAzCC
AtwwggJFoAMCAQICEApLTm3bM9PFZxFEfV6XkZAwDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UE
BhMCWkExJTAjBg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