[LLVMdev] getElapsedWallTime unnecessary heap allocation and memory leak
Caldarale, Charles R
Chuck.Caldarale at unisys.com
Wed Mar 19 06:41:41 PDT 2014
> 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
More information about the llvm-dev
mailing list