On Sun, 9 Nov 2014, Tomas Hajny wrote:
On 9 Nov 14, at 21:58, Xiangrong Fang wrote:
Hi Xiangrong,
I use heap trace utility to see if there are memory leak in my program.
The source is here:
https://github.com/xrfang/fpcollection/blob/aefa04f0374c94298facd8d57d4a25dafe10b753/src/demos/cache/demo.lpr
My problem is, at the beginning of the main program, I have a costant
definition:
const
ITEM_COUNT = 5000000;
If I set ITEM_COUNT to a small value, say 50 or 5000, everything is OK, no
memory leak. But with the above value, it will cause HEAPTRC to fall in an
endless loop, generating messages like:
Call trace for block $00007F41693AA680 size 40
$000000000040071F line 29 of demo.lpr
$0000000000400180
While line 29 is this:
27 for i := 0 to ITEM_COUNT - 1 do begin
28 for j := 0 to 4 do key[j] := $deadbeef + i + j;
29 h.Add(@key, SizeOf(PtrUInt) * 5, Pointer($deadbeef + i));
30 end;
Could anyone tell me why heaptrc will fall in an endless loop, and does my
program have memory leak?
Are you sure that it really is endless (i.e. did you let to run for a
sufficiently long time)? If you increase the amount of allocated
blocks (which is what happens in case of increasing your constant),
traversing through all the blocks (especially if they are not freed
at the end) may indeed take fairly long time...
It is not endless. I tested, it simply takes several minutes to
produce a stack trace for 2910911 (yes, 3 million) unfreed blocks
of memory. The resulting heap.trc file is 300Mb.
Michael.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal