<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 6:18 PM, Bryan Keiren <span dir="ltr"><<a href="mailto:bryan.keiren@guerrilla-games.com" target="_blank">bryan.keiren@guerrilla-games.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We are indeed trying to completely clean the heap before exiting main().<br></blockquote><div><br></div><div>Which means that you either don't have threads, or you join all threads before main exits.</div>
<div>Is that the case?</div><div>Good for you if so! </div><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"><br>
<br>
-----Original Message-----<br>
From: Caldarale, Charles R [mailto:<a href="mailto:Chuck.Caldarale@unisys.com">Chuck.Caldarale@unisys.com</a>]<br>
Sent: Wednesday, March 19, 2014 14:42<br>
To: Bryan Keiren; <a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
Subject: RE: [LLVMdev] getElapsedWallTime unnecessary heap allocation and memory leak<br>
<br>
> From: <a href="mailto:llvmdev-bounces@cs.uiuc.edu">llvmdev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvmdev-bounces@cs.uiuc.edu">llvmdev-bounces@cs.uiuc.edu</a>]<br>
> On Behalf Of Bryan Keiren<br>
> Subject: [LLVMdev] getElapsedWallTime unnecessary heap allocation and<br>
> memory leak<br>
<br>
> In the file \lib\Support\Process.cpp on line 60, it seems as though an<br>
> unnecessary heap allocation and memory leak occurs.<br>
<br>
> static TimeValue getElapsedWallTime() {<br>
>  static TimeValue &StartTime = *new TimeValue(TimeValue::now());<br>
>  return TimeValue::now() - StartTime;<br>
> }<br>
<br>
> The issue is that the StartTime variable's value is allocated on the<br>
> heap, after which a *reference* to it is stored (not the pointer<br>
> itself). This means that the allocated memory is actually never properly de-allocated.<br>
<br>
Since the StartTime field is static, why is this considered a leak?  The reference has not been lost and is utilized whenever getElapsedWallTime() is invoked.  Although it might be infinitesimally more efficient to avoid the new operator, the overall memory consumption is almost identical.<br>

<br>
Are you trying to get rid of the entire heap at some point before process termination?<br>
<br>
 - Chuck<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div></div>