[CppAD] possible memory leak

schattenpflanze at arcor.de schattenpflanze at arcor.de
Fri Jul 15 12:36:35 EDT 2011


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_1.cpp
Type: text/x-c++src
Size: 743 bytes
Desc: not available
Url : http://list.coin-or.org/pipermail/cppad/attachments/20110715/9790030b/attachment.bin 


More information about the CppAD mailing list