[CppAD] possible memory leak

Brad Bell bradbell at seanet.com
Sat Jul 16 00:20:51 EDT 2011


Using a special OpenMP memory manager turned out to greatly improve 
CppAD speed tests. This has enabled CppAD  to obtain near linear speed 
ups for 40 cores (we have not yet tested more cores); see the heading 
05-22 on
http://www.coin-or.org/CppAD/Doc/whats_new_11.xml#05-22

This new memory manager holds onto memory until the following function 
is called
http://www.coin-or.org/CppAD/Doc/free_available.xml

On 7/15/2011 9:36 AM, schattenpflanze at arcor.de wrote:
>
> I had a look into this. The "memory leak" is due to the fact that
> free_available(0) is never called. Thus, the omp_alloc memory manager
> never really frees the memory, but rather stores it for possible future
> use. Moreover, even if free_available(0) is called before the end of
> main(), the created ADFun object is still in scope. Thus, its memory
> cannot yet be freed.
This makes sense; see
     http://www.coin-or.org/CppAD/Doc/inuse.xml
> If I define the ADFun object within a block scope and call
> free_available(0) after that block closes (see attachment), no memory
> leak is detected by valgrind.
Thanks for checking this.
> We should definitely find a way to free all memory automatically at the
> end of a program. I suggest calling free_available() for every thread
> (up to the number set in max_num_threads) in the destructor of some
> auxiliary class A, and including an object of that type as a static
> class member of AD<Base>  (or any other class).
>
> In addition, we could also think about deleting returned memory by
> default, and only activating the current behaviour (storing returned
> memory as "available") on user request. Something like
> omp_alloc::keep_memory_available(bool setting).
Perhaps the memory allocator should not hold onto memory that was 
allocated during sequential (not parallel) mode ?

That way, free_available during sequential mode could return all the 
memory to the system (provided that the variables allocated during 
parallel mode have dropped out of scope by the time we reach sequential 
mode).

> Best regards,
> Peter
>
>
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cppad

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/cppad/attachments/20110715/0763c966/attachment.html 


More information about the CppAD mailing list