Re: [gdome]reference counts and freeDoc
- From: Paolo Casarini <casarini CS UniBO IT>
- To: Tobias Peters <tpeters uni-oldenburg de>
- Cc: gdome gnome org
- Subject: Re: [gdome]reference counts and freeDoc
- Date: Thu, 14 Jun 2001 16:12:30 +0200 (CEST)
On Thu, 14 Jun 2001, Tobias Peters wrote:
> Do all functions returning a Gdome... object increase that object's
> reference count?
Yes, all function return always a fresh/new reference and you become the
owner of this reference. When you become the "owner" of a reference, you
have to unref it when it is no longer used.
> So after
>
> GdomeElement* el = gdome_doc_documentElement(doc, exc);
> el = gdome_doc_documentElement(doc, exc);
>
> the element node pointed to by el has reference count 2 ?
Yes.
> Does gdome_doc_unref do the same thing as gdome_di_freeDoc when its
> reference count reaches zero?
no, gdome_doc_unref work only on the reference counting of the
GdomeDocument object. gdome_di_freeDoc work on the internal
rappresentation of a document:
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);
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.
> What happens when some nodes in this document are still being referenced?
This is a problem not yet resolved. Daniel should implement, in a few
month, in libxml2 a callback to signal when it frees a node. With this I
can set to NULL the GdomeNode internal pointer to the xmlNode and if a
Gdome2 user try to access to an not valid refrence I can raise a
GDOME_NULL_POINTER_ERR.
To answer to your last question, you can call only methods
that works with the reference counting on it like gdome_xx_unref,
gdome_xx_ref on it.
To understand better the memory management of Gdome2 you can read the
article I wrote with Luca Padovani (you can find it on the Gdome2
site: http://www.cs.unibo.it/~casarini/gdome2/ in the documentation
section). The article version you can find on web is an old version
and something has changed in Gdome2. I hope I can publish the new version
soon.
Bye
Paolo
--
Paolo Casarini - casarini cs unibo it
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]