Re: [gdome]reference counts and freeDoc



On Fri, 15 Jun 2001, Tobias Peters wrote:

> 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.
In my mind this is not a problem: one thing is loading and unloading a
document (createDOC... and freeDoc) and one thing is working on it with
refrences (ref, unref, ...). Nevertheless, I can change something... I
want to talk about this in the mailing list so we can try to find the best  
solution, I try to make 3 possible solution:
1- gdome_di_freeDoc also free the reference to the GdomeDocument object
passed as argument.
2- gdome_doc_unref also free the document structure when its refcnt reach
0.
3- gdome_di_freeDoc also free all the reference that point to the Document
specified (For this I've to save a pointer to all active references).

To me, the first is the best, but also the second could be right. The
third one implies a increment of the memory usage.
  
> > 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.
This is true. I'll fix this problem with one of the previous three
methods. 

> 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.
Don't worry about this, I'll change it soon.

> 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)?
The proper way to end working on a Document is with the
gdome_di_freeDoc. After you call the gdome_di_freeDoc you can't do
anything with any refrence to the document freed.
So we have a memory leak because we can't unref the last reference to the
GdomeDocument used to call gdome_di_freeDoc.
 
Bye
   Paolo
--
Paolo Casarini - casarini cs unibo it





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