[CppAD] possible memory leak

Brad Bell bradbell at seanet.com
Sat Jul 30 10:02:59 EDT 2011


CppAD has been modified so that if multiple threads are not used, the 
user does not need to deal with the more complex memory management 
aspects of omp_alloc. To be specific, if the function
     CppAD::omp_alloc::set_max_num_threads
is not called, the memory management (from the users point of view) has 
not changed. I think that this satisfied the request below.

See the documentation for return_memory
     http://www.coin-or.org/CppAD/Doc/return_memory.htm
and the whats new headings 07-28 and 07-29 on
     http://www.coin-or.org/CppAD/Doc/whats_new_11.htm#07-28

Note that the function max_num_threads has been replaced by 
set_max_num_threads and the function get_max_num_threads has been added 
to the user API.


On 7/15/2011 9:36 AM, schattenpflanze at arcor.de wrote:
> Brad,
>
>> [snip]
>> So there seems to be a memory leak. It would be nice, if this could be
>> fixed.
> 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.
> 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.
>
> 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).
>
>
> 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/20110730/6b13c8ff/attachment.html 


More information about the CppAD mailing list