[gdome]memory management



Hello,

I thought I could possibly help implementing the new memory management
model as suggested by Paolo in message
<Pine LNX 4 21 0107101739540 24500-100000 ferrando cs unibo it>, so I did
some investigation last night.

I added an int livenodes field to the Gdome_xml_Document struct,
introduced
- gdome_xml_doc_mkref,
- gdome_xml_doc_ref,
- gdome_xml_doc_add_livenode,
- gdome_xml_doc_unref and
- gdome_xml_doc_remove_livenode

functions, and modified gdome_xml_n_mkref accordingly -- or at least I
thought so. The attached archive contains a patch
"doc_livenodes_memory_management_patch" against the current CVS archive
that compiles ok but does not solve the memory leak problem. Maybe you can
make some use of it.

Then I tried the another approach, this time without modifying the data
structure, using the refcnt field of Gdome_xml_Document for counting the
sum of document references and existing live nodes. This was easier to
implement, only gdome_xml_n_mkref and gdome_xml_n_unref were changed, and
it works. There is a patch "doc_refcnt_memory_management_patch" against
the libgdome-0.6.9 release in the attached archive.

This change works as expected, and it is compatible with older programs
that call gdome_xml_di_freeDoc: The old memory management model is the
default for every fresh document (there is a difference though: the
document node always stays in memory and its refcnt field values are
higher, but this should not affect users, since they cannot see the
refcnt field). Users wanting to have their documents managed automatically
have to perform an extra function call -- see the comments included in the
patch.

Also in the archive is a little test programm that builds and destroys a
dom tree 20000 times -- it is intended that you watch the memory usage of
this program with a tool like "top". I wrote it originally for the
livenodes approach, but with the extra function call added it works fine
with the refcnt approach.

Bye, Tobias

Attachment: gdome_memory_management.tar.bz2
Description: Binary data



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