Re: [xml] Memory leak / cleanup missing after node creation.
- From: Igor Zlatkovic <igor zlatkovic com>
- To: Jose Commins <axora myrealbox com>
- Cc: xml gnome org
- Subject: Re: [xml] Memory leak / cleanup missing after node creation.
- Date: Tue, 25 May 2004 14:04:22 +0200
On 25.05.2004 04:00, Jose Commins wrote:
Thanks again Igor! During the process I also found some more memory
oddness - the following below doesn't register as a leak using 'leaks'
in FreeBSD Terminal, but I see the memory go up:
>
In my (multithreaded) app I have x amount of buffers allocated with:
theFinalXML = xmlBufferCreateSize(8192);
If, for example, I perform a 'xmlBufferLength(theFinalXML)' I get
back zero. Er, OK, weird, since I thought 'xmlBufferCreateSize' can
pre-allocate a known size so the buffer doesn't need to be constantly
re-malloc'ed (or whatever scheme it uses).
So if I dump the buffer (this is in my main thread loop):
theFinalXMLSize = xmlNodeDump(theFinalXML, doc, root_element, 0, 0);
I *have* to perform:
xmlBufferEmpty(theFinalXML);
afterwards, otherwise the buffers grow and grow. Um, I am fine with
using BufferEmpty (apart from the performace hit of constant allocs and
reallocs), but then what use has 'xmlBufferCreateSize' ?
No reallocation has happened unless your nodes, in the serialised form,
were bigger than 8k. More, xmlBufferEmpty does not free any memory, it
just erases the content, so it cannot be that calling this function
makes your buffer memory smaller.
xmlBufferCreateSize creates a buffer with the specified initial size and
allocates its memory. xmlBufferLength returns the length of the content.
After you created the buffer, you haven't written any data in it yet, so
the content length is 0. But the memory of the specified size has been
allocated. If you write no more than the initial size into the buffer,
no reallocation will occur.
When you write more data into a buffer than it can hold, the buffer will
grow automatically. It will however never shrink automatically, that you
must tell it to do explicitly (xmlBufferShrink) but this operation
probably does not do what you think it does.
Ciao,
Igor
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]