<div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace">You are right, the bug is fixed, and another bug in the GetEnumerator are also found and fixed. </div><div class="gmail_default" style="font-family:courier new,monospace">
<br></div><div class="gmail_default" style="font-family:courier new,monospace">This is my first time using heaptrc.</div><div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_default" style="font-family:courier new,monospace">
Thanks a lot.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/27 Jeppe Græsdal Johansen <span dir="ltr"><<a href="mailto:jeppe@j-software.dk" target="_blank">jeppe@j-software.dk</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div>Den <a href="tel:27-12-2013%2010" value="+862712201310" target="_blank">27-12-2013 10</a>:16, Xiangrong Fang
skrev:<br>
</div><div><div class="h5">
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_default">Hi All,</div>
<div class="gmail_default"><br>
</div>
<div class="gmail_default">
I used HeapTrc on my TTreap class:</div>
<div class="gmail_default"><br>
</div>
<div class="gmail_default"><a href="https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas" target="_blank">https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas</a><br>
</div>
<div class="gmail_default"><br>
</div>
<div class="gmail_default">It reported memory leak in the following
procedure:</div>
<div class="gmail_default">
<pre style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px"><div style="padding-left:10px"><span style="font-weight:bold">
</span></div><div style="padding-left:10px"><span style="font-weight:bold">function</span> <span style="color:rgb(68,85,136);font-weight:bold">TTreap</span><span style="font-weight:bold">.</span><span style="color:rgb(153,0,0);font-weight:bold">GetEnumerator</span><span style="font-weight:bold">:</span> <span>TTreap</span><span style="font-weight:bold">;</span></div>
<div style="padding-left:10px"><span style="font-weight:bold">begin</span></div><div style="padding-left:10px"> <span style="color:rgb(153,153,153)">Result</span> <span style="font-weight:bold">:=</span> <span>TTreap</span><span style="font-weight:bold">.</span><span>Create</span><span style="font-weight:bold">; //<-- memory leak here</span></div>
<div style="padding-left:10px"> <span style="color:rgb(153,153,153)">Result</span><span style="font-weight:bold">.</span><span>ProxyFor</span> <span style="font-weight:bold">:=</span> <span style="font-weight:bold">Self</span><span style="font-weight:bold">;</span></div>
<div style="padding-left:10px"><span style="font-weight:bold"> ... ...</span></div><div style="padding-left:10px"><span style="font-size:12px;line-height:18px;font-weight:bold">end</span><span style="font-size:12px;line-height:18px;font-weight:bold">;</span></div>
<div style="padding-left:10px"><span style="font-size:12px;line-height:18px;font-weight:bold">
</span></div></pre>
</div>
<div class="gmail_default">
Typical usage of the TTreap enumerator is:</div>
<div class="gmail_default"><br>
</div>
<div class="gmail_default">
<div class="gmail_default">
<pre style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px"><div style="padding-left:10px"> <span style="font-weight:bold">for</span> <span>n</span> <span style="font-weight:bold">in</span> aTreap <span style="font-weight:bold">do</span> <span style="font-weight:bold">begin</span></div>
<div style="padding-left:10px"> //do something with n</div><div style="padding-left:10px"><span style="font-size:12px;line-height:18px"> </span><span style="font-size:12px;line-height:18px;font-weight:bold">end</span><span style="font-size:12px;line-height:18px;font-weight:bold">;</span></div>
<div><span style="font-size:12px;line-height:18px;font-weight:bold">
</span></div></pre>
</div>
</div>
<div class="gmail_default">My question is: will the for-loop
automatically free the enumerator after usage? How to fix
leaks in my ttreap class?</div>
<div class="gmail_default"><br>
</div>
<div class="gmail_default">Thanks a lot!</div>
<div class="gmail_default">
<br>
</div>
<div class="gmail_default">Xiangrong</div>
<br>
</div>
</blockquote></div></div>
Your constructor allocates a new NullNode, which gets overwritten in
GetEnumerator, and hence the enumerator NullNode is never freed.<br>
<br>
</div>
<br>_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br></blockquote></div><br></div>