<div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace"><span style="font-family:arial">2014-11-09 22:38 GMT+08:00 Michael Van Canneyt </span><span dir="ltr" style="font-family:arial"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span><span style="font-family:arial">:</span><br></div><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><span style="color:rgb(34,34,34)">Code like this:</span><br></div></div>
<br>
ci := PCacheItem((buf + SizeOf(Pointer) * Random(FDepth))^);<br>
for i := 0 to FDepth - 1 do begin<br>
slot := buf + SizeOf(Pointer) * i;<br>
if Pointer(slot^) = nil then begin<br>
Inc(N);<br>
Pointer(slot^) := GetMem(SizeOf(TCacheItem));<br>
ci := PCacheItem(slot^);<br>
<br>
makes me frown, because the first assignment to ci is useless, so highly suspect.</blockquote><div><br></div><div><div class="gmail_default" style="font-family:'courier new',monospace;display:inline">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.</div></div><div><div class="gmail_default" style="font-family:'courier new',monospace;display:inline"><br></div></div><div><div class="gmail_default" style="font-family:'courier new',monospace;display:inline">Thanks!</div></div><div><div class="gmail_default" style="font-family:'courier new',monospace;display:inline"><br></div></div><div><div class="gmail_default" style="font-family:'courier new',monospace;display:inline">Xiangrong.</div> </div></div></div></div>