This is a cryptographically signed message in MIME format.

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

Hi Nobu,

> At Thu, 10 Jul 2008 03:40:52 +0900,
> Charlie Savage wrote in [ruby-core:17706]:
>> Hmm.  To correctly shut down my extension, I do need to control the 
>> order in which the objects are freed.  Is there any way to do this?  And 
>> have other people run into this issue (seems like it would be common 
>> when freeing resources allocated from a 3rd party library, in this case 
>> libxml).
> 
> Which object is the problem?  Reference count may be useful.

The specifics of this issue are:

1.  Open a XML::Document
2.  Call Document#find which returns an XML::Node::Set
3.  Within libxml, XML::Node::Set maintains a set of pointers to nodes 
that are owned by the document.
4.  Ruby process starts exiting
5.  XML::Document is freed
6.  XML::Node::Set is freed - but when it iterates over its list of 
nodes to pointers a segmentation fault occurs.

If the order is reversed then there is no problem.  It is possible to 
code around this by having Documents maintain pointers to returned 
Node::Sets and Node::Sets in turn link back to their parent documents. 
But that all seems like a big kludge around the fact that the order of 
free calls is random, even though the Node::Set does have an appropriate 
mark function.

It seems to me this must be a common thing that should have a built-in 
solution.  It would be nice if Ruby could do one mark/sweep/free before 
shutting down a process.  Or if that is too much, then a lighter weight 
way of saying Object A must be freed before Object B (well, the whole 
idea of mark and sweep again).

In this case, I can't see how reference counting would help....

Charlie



--------------ms070303050609050308080505
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
BhMCWkExJTAjBgNVBAoTHFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMT
I1RoYXd0ZSBQZXJzb25hbCBGcmVlbWFpbCBJc3N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