Re: [gdome]reference counts and freeDoc



Am 14.06.01, 16:12:30, schrieb Paolo Casarini <casarini CS UniBO IT> zum 
Thema Re: [gdome]reference counts and freeDoc:
> A document can be in memory also if there's no reference to it: to free a
> DOM you have to call the gdome_di_freeDoc (it free the libxml2 tree
> structure);
That's not nice. Gdome mixes two different memory allocation shemes: 
Reference conting implies that you do not need to worry about when to 
delete your memory, you only need to keep track of your usage locally. 
The library knows when it is time to free the memory.

> You have not to save a GdomeDocument reference till the end of your work
> because you can get a reference to a GdomeDocument with the
> gdome_xx_ownerDocument method on any node of document.
Yes. But you have to know wether the node that you are just about to 
unref is possibly the last reference to the whole document, and if this 
node's reference count will reach zero by this call to unref. This may be 
trivial in some programs. I don't think it is always.

I think I can handle this in my wrapper. I need to keep track of all 
allocated nodes per document, and have a look at the internal reference 
count before each call to unref, to know when a node is about to be 
deleted again, and erase it from my list. Then, before the last node of a 
document is deleted, I also call gdome_di_freeDoc.

BTW which is the proper order to call both gdome_di_freeDoc and 
gdome_doc_unref (assuming this document node is the last reference to the 
document)?

While I am willing to implement this in my wrapper, I really think it 
belongs into gdome itself, since keeping track of your memory usage is 
not specific to ruby.

> To understand better the memory management of Gdome2 you can read the
> article I wrote with Luca Padovani

thanks for the pointer.

Tobias




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]