<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div>Hope I can explain it clear enough :-)</div><div><br></div><div>> MemReclaimer has two containers to hold pointers of TreePatternNode & TreePattern which are allocated from heap.</div><div>> Only one global instance of <span style="line-height: 23.7999992370605px;">MemReclaimer</span><span style="line-height: 23.7999992370605px;">  is declared -- memReclaimer.</span></div><div><span style="line-height: 23.7999992370605px;">> operator new & operator delete are defined for </span><span style="line-height: 23.7999992370605px;">TreePatternNode & TreePattern </span></div><div><span style="line-height: 23.7999992370605px;">          new:    push the new allocated object (pointer) into containers in </span><span style="line-height: 23.7999992370605px;">memReclaimer.</span></div><div><span style="line-height: 23.7999992370605px;">          delete: remove the pointer from the containers in </span><span style="line-height: 23.7999992370605px;">memReclaimer.</span></div><div><span style="line-height: 23.7999992370605px;"><br></span></div><div><span style="line-height: 23.7999992370605px;">          So we can </span>guarantee that objects allocated from heap can always be recorded by <span style="line-height: 23.7999992370605px;">memReclaimer.</span><span style="line-height: 23.7999992370605px;"> </span></div><div><span style="line-height: 23.7999992370605px;">          And no double free may incur, as some places in the source delete some pointers manually (maybe we can remove these lines</span><span style="line-height: 23.7999992370605px;">).</span></div><div><span style="line-height: 23.7999992370605px;">> So memReclaimer only keeps the objects that are leaked in current design.</span></div><div><span style="line-height: 23.7999992370605px;">> the author of </span><span style="line-height: 23.7999992370605px;">CodeGenDAGPattern </span><span style="line-height: 23.7999992370605px;"> create nodes, but destroy part of them (for TreePattern, the nodes </span><span style="line-height: 1.7;">destroyed</span><span style="line-height: 23.7999992370605px;"> manually account for more than 30%, </span></div><div><span style="line-height: 23.7999992370605px;">          for some target even over 50%; while for TreePatternNode  only around 1%) and make the rest leaked deliberately.</span></div><div>> dtor of <span style="line-height: 23.7999992370605px;">CodeGenDAGPattern now is the place to </span>destroy<span style="line-height: 23.7999992370605px;"> all not freed objects</span></div><div><span style="line-height: 23.7999992370605px;">> move the functionality of </span><span style="line-height: 23.7999992370605px;">MemReclaimer</span><span style="line-height: 23.7999992370605px;"> into </span><span style="line-height: 23.7999992370605px;">CodeGenDAGPattern </span><span style="line-height: 23.7999992370605px;"> is definitely feasible I think.</span></div><div><br></div><div>Regards</div><div>Hui Wu</div><div><br></div><div></div><div id="divNeteaseMailCard"></div><br>At 2014-11-11 14:20:25, "David Blaikie" <dblaikie@gmail.com> wrote:<br> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><div dir="ltr">Could you describe the high level design here?<br><br>It looks like there's a static pool (CodeGenDAGPatterns.cpp::memReclaimer) of instances that's used as some kind of last-chance cleanup? Instances of TreePatternNode mostly manage their own lifetime but then if any haven't been destroyed by the time the CodeGenDAGPatterns dtor runs, the remaining elements are destroyed. This is to handle cycles, I take it?<br><br>It still seems like a bit of a GC-esque workaround to handle this case when there might be something better... but I don't know much about tablegen, perhaps there isn't.<br><br>How often are nodes destroyed by themselves? Should we just give up owning these anywhere else & move all ownership into CodeGenDAGPatterns and clean them up in CodeGenDAGPatterns' dtor? (just have a vector of unique_ptrs (maybe even a list or deque of nodes directly owned, rather than via unique_ptr), only create nodes, never destroy them, then destroy them all at the end)</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 10, 2014 at 9:58 PM, wuhui1973 <span dir="ltr"><<a href="mailto:wuhui1973@163.com" target="_blank">wuhui1973@163.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px">Hi Andrew, David and Hal:</span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px"><br></span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px">I have made a new solution for this memory leak issue, which is much simpler than previous one. </span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px"><br></span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px">I have tested it, it works well!</span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px"><br></span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px">Please have a look, and appreciate any comment.</span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px"><br></span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px">Thanks & Regards</span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px"><br></span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span style="line-height:23.7999992370605px">Hui Wu</span></div><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><br></div></div><span title="neteasefooter"><span></span></span></div><br><br><span title="neteasefooter"><span></span></span></blockquote></div><br></div>
</blockquote></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>