[Lazarus] XML and memory loss

Sergei Gorelkin sergei_gorelkin at mail.ru
Wed Oct 8 17:49:28 CEST 2008


Bart wrote:

...
 >
> This file is more or less as I excpected it to be (i would think it 
> would include the encoding="utf-8").

Currently changing the encoding is not supported, and files are always 
written in utf-8 encoding. According to the XML specs, files without 
encoding label are read as utf-8, so this is by design.
> 
> The problem is, that for every child I create and append, I loose 4 
> blocks of memory (60 bytes for these 4 blocks) (I used the heaptrace 
> option with compilation).

The memory leak is caused by using the ChildNodes property. Each time 
you use it, a new TDOMNodeList object is created, which must be 
eventually destroyed by calling Free. The FCL DOM implementation does 
not offer automatic memory management here, unlike other implementations.

Some time ago I updated the English page of Wiki tutorial to reflect 
this fact.

In your case, ChildNodes.Item[0] can be replaced by FirstChild, which 
will return exactly the same node.

Regards,
Sergei




More information about the Lazarus mailing list