[LLVMdev] getElapsedWallTime unnecessary heap allocation and memory leak

Alexey Samsonov samsonov at google.com
Wed Mar 19 08:58:04 PDT 2014


On Wed, Mar 19, 2014 at 6:42 PM, Bryan Keiren <
bryan.keiren at guerrilla-games.com> wrote:

>  I’m not involved with however our threading is implemented or used ;)
> All I know is that we’re trying to match each allocation with a
> de-allocation and the way the LLVM code currently works is not compatible
> with this philosophy. Because we felt this might have been an issue with
> LLVM itself we decided to go here and ask you guys.
>
>
>
> We will probably just patch LLVM locally (argh, I can already hear the
> muttered curses of the people who have to re-patch a future version
> upgrade… Haha).
>

As Kostya mentioned, requiring that each allocated chunk of memory should
be deallocated before exiting main() is rather impractical for C++, as this
wouldn't work in multithreaded environment where the memory should be
accessible by threads even after main() exits, and threads can't be joined
because there can be no valid shutdown order. Even if you can guarantee
this doesn't happen in your setting, it isn't so for all users of LLVM
libraries.


>
>
>
>
> *From:* Kostya Serebryany [mailto:kcc at google.com]
> *Sent:* Wednesday, March 19, 2014 15:29
> *To:* Bryan Keiren
> *Cc:* Caldarale, Charles R; llvmdev at cs.uiuc.edu
> *Subject:* Re: [LLVMdev] getElapsedWallTime unnecessary heap allocation
> and memory leak
>
>
>
>
>
>
>
> On Wed, Mar 19, 2014 at 6:18 PM, Bryan Keiren <
> bryan.keiren at guerrilla-games.com> wrote:
>
> We are indeed trying to completely clean the heap before exiting main().
>
>
>
> Which means that you either don't have threads, or you join all threads
> before main exits.
>
> Is that the case?
>
> Good for you if so!
>
>
>
>
>
> -----Original Message-----
> From: Caldarale, Charles R [mailto:Chuck.Caldarale at unisys.com]
> Sent: Wednesday, March 19, 2014 14:42
> To: Bryan Keiren; llvmdev at cs.uiuc.edu
> Subject: RE: [LLVMdev] getElapsedWallTime unnecessary heap allocation and
> memory leak
>
> > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu]
> > On Behalf Of Bryan Keiren
> > Subject: [LLVMdev] getElapsedWallTime unnecessary heap allocation and
> > memory leak
>
> > In the file \lib\Support\Process.cpp on line 60, it seems as though an
> > unnecessary heap allocation and memory leak occurs.
>
> > static TimeValue getElapsedWallTime() {
> >  static TimeValue &StartTime = *new TimeValue(TimeValue::now());
> >  return TimeValue::now() - StartTime;
> > }
>
> > The issue is that the StartTime variable's value is allocated on the
> > heap, after which a *reference* to it is stored (not the pointer
> > itself). This means that the allocated memory is actually never properly
> de-allocated.
>
> 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.
>
> Are you trying to get rid of the entire heap at some point before process
> termination?
>
>  - Chuck
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>


-- 
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140319/deb74910/attachment.html>


More information about the llvm-dev mailing list