<div dir="ltr"><div class="gmail_default" style="font-family:'courier new',monospace">Hi All,</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">
I used HeapTrc on my TTreap class:</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace"><a href="https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas">https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas</a><br>
</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">It reported memory leak in the following procedure:</div>
<div class="gmail_default" style="font-family:'courier new',monospace"><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 class="" id="LC315" style="padding-left:10px"><span class="" style="font-weight:bold"><br></span></div><div class="" id="LC315" style="padding-left:10px"><span class="" style="font-weight:bold">function</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">TTreap</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(153,0,0);font-weight:bold">GetEnumerator</span><span class="" style="font-weight:bold">:</span> <span class="">TTreap</span><span class="" style="font-weight:bold">;</span></div>
<div class="" id="LC316" style="padding-left:10px"><span class="" style="font-weight:bold">begin</span></div><div class="" id="LC317" style="padding-left:10px"> <span class="" style="color:rgb(153,153,153)">Result</span> <span class="" style="font-weight:bold">:=</span> <span class="">TTreap</span><span class="" style="font-weight:bold">.</span><span class="">Create</span><span class="" style="font-weight:bold">; //<-- memory leak here</span></div>
<div class="" id="LC318" style="padding-left:10px"> <span class="" style="color:rgb(153,153,153)">Result</span><span class="" style="font-weight:bold">.</span><span class="">ProxyFor</span> <span class="" style="font-weight:bold">:=</span> <span class="" style="font-weight:bold">Self</span><span class="" style="font-weight:bold">;</span></div>
<div class="" id="LC318" style="padding-left:10px"><span class="" style="font-weight:bold"> ... ...</span></div><div class="" id="LC319" style="padding-left:10px"><span class="" style="font-size:12px;line-height:18px;font-weight:bold">end</span><span class="" style="font-size:12px;line-height:18px;font-weight:bold">;</span></div>
<div class="" id="LC319" style="padding-left:10px"><span class="" style="font-size:12px;line-height:18px;font-weight:bold"><br></span></div></pre></div><div class="gmail_default" style="font-family:'courier new',monospace">
Typical usage of the TTreap enumerator is:</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace"><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 class="" id="LC73" style="padding-left:10px"> <span class="" style="font-weight:bold">for</span> <span class="">n</span> <span class="" style="font-weight:bold">in</span> aTreap <span class="" style="font-weight:bold">do</span> <span class="" style="font-weight:bold">begin</span></div>
<div class="" id="LC74" style="padding-left:10px"> //do something with n</div><div class="" id="LC74" style="padding-left:10px"><span style="font-size:12px;line-height:18px"> </span><span class="" style="font-size:12px;line-height:18px;font-weight:bold">end</span><span class="" style="font-size:12px;line-height:18px;font-weight:bold">;</span></div>
<div><span class="" style="font-size:12px;line-height:18px;font-weight:bold"><br></span></div></pre></div></div><div class="gmail_default" style="font-family:'courier new',monospace">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" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">Thanks a lot!</div><div class="gmail_default" style="font-family:'courier new',monospace">
<br></div><div class="gmail_default" style="font-family:'courier new',monospace">Xiangrong</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">
<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 class="" id="LC73" style="padding-left:10px"><br></div>
</pre></div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace"><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 class="" id="LC315" style="padding-left:10px"><br></div><div class="" id="LC319" style="padding-left:10px"><br></div></pre></div></div>