[fpc-pascal] Problem with heaptrc

Xiangrong Fang xrfang at gmail.com
Sun Nov 9 15:41:41 CET 2014


2014-11-09 22:38 GMT+08:00 Michael Van Canneyt <michael at freepascal.org>:


> Code like this:
>
>    ci := PCacheItem((buf + SizeOf(Pointer) * Random(FDepth))^);
>     for i := 0 to FDepth - 1 do begin
>       slot := buf + SizeOf(Pointer) * i;
>       if Pointer(slot^) = nil then begin
>         Inc(N);
>         Pointer(slot^) := GetMem(SizeOf(TCacheItem));
>         ci := PCacheItem(slot^);
>
> makes me frown, because the first assignment to ci is useless, so highly
> suspect.


​You are right Michael.  I just found that if there is no free slot, I use
"Random Replacement" to dump one of the existing cached item, whose key is
not freed, which caused memory leak.

Thanks!

Xiangrong.​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141109/79649840/attachment.html>


More information about the fpc-pascal mailing list