[Lazarus] RE : RE : RE : RE : RE : RE : Console App Development

Ludo Brands ludo.brands at free.fr
Mon Aug 15 16:14:29 CEST 2011


> So I did another test.
> 
> I added at the end of SynEdit. destroy:
>    GetMemoryManager(m);
>    debugln(['****************** ',m.GetFPCHeapStatus().CurrHeapUsed])
> 
> That would show any memory allocated by pascal code. (but not memory 
> that qt or w32 keep for some reason (even though the reason might be 
> missing release calls by the pascal code...))
> 
> The initial sizes are matching the measurements taken by 
> process-explorer (w32)
> 
>   41870000   open lazarus, with about a dozen units - close 
> one unit, to 
> trigger the output
> 198591312  open  450 univint - close one unit, to trigger the output
>   63014880  close all 450 univint  => ok so some meory was kept
> 
> 193982864  open 450 univint - close one unit, to trigger the 
> output => 
> hey we are even lower than last tim
>   62963664   close all 450 univint => no extra memory kept on 2nd run
> 
> 194002192 open again
>   63734976 close again
> 193996224 open
>   63027440 close
> 
> So that means:
> - there may be memory allocated by the widgetset; some of 
> this may not 
> be returned (and heaptrc would not report this as leak)
>   IF some of this isn not returned, then this might be an issue in 
> Lazarus/LCL, BUT it could also be an issue of the widgetset itself.
> 
> - A huge amount of memory is allocated by pascal code, via the memory 
> manager.
> - Most of it is returned correctly.
> - A certain amount is allocated and kept => but it does not increase
> 
> 
> Those tests were done using heaptrc
> 
> 

I noticed the TCodeCache created in DoOpenEditorFile with LoadCodeBuffer
aren't destroyed when closing the editorfiles. In DoCloseEditorFile the
IsDeleted is set which sets FSource to ''. So that should be fine. Under
gtk2 however, one has to prudent here, I traced into DoCloseEditorFile and
noticed that the refcount for FSource was 2 before setting it to '' on all
but the first file. This means that somebody has made a copy of the source
and is hanging on to it. As mentioned before, on gtk2, DoOpenEditorFile
allocated memory that continued to grow.

On windows I also tracked a particular FSource address across multiple
project loads/unloads and the original source was kept in memory until
lazarus closed. The debugger in lazarus didn't allow me to inspect the
refcount of the string  though and crashed on me. So this is no proof. I'll
have to redo this test.

Ludo






More information about the Lazarus mailing list