<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    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<br>
    &nbsp;&nbsp;&nbsp; CppAD::omp_alloc::set_max_num_threads<br>
    is not called, the memory management (from the users point of view)
    has not changed. I think that this satisfied the request below.<br>
    <br>
    See the documentation for return_memory<br>
    &nbsp;&nbsp;&nbsp; <a class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/return_memory.htm">http://www.coin-or.org/CppAD/Doc/return_memory.htm</a><br>
    and the whats new headings 07-28 and 07-29 on<br>
    &nbsp;&nbsp;&nbsp; <a class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/whats_new_11.htm#07-28">http://www.coin-or.org/CppAD/Doc/whats_new_11.htm#07-28</a><br>
    <br>
    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.<br>
    <br>
    <br>
    On 7/15/2011 9:36 AM, <a class="moz-txt-link-abbreviated" href="mailto:schattenpflanze@arcor.de">schattenpflanze@arcor.de</a> wrote:
    <blockquote cite="mid:4E206C93.1030607@arcor.de" type="cite">
      <pre wrap="">Brad,

</pre>
      <blockquote type="cite">
        <pre wrap="">[snip]
So there seems to be a memory leak. It would be nice, if this could be 
fixed.
</pre>
      </blockquote>
      <pre wrap="">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&lt;Base&gt; (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
</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
CppAD mailing list
<a class="moz-txt-link-abbreviated" href="mailto:CppAD@list.coin-or.org">CppAD@list.coin-or.org</a>
<a class="moz-txt-link-freetext" href="http://list.coin-or.org/mailman/listinfo/cppad">http://list.coin-or.org/mailman/listinfo/cppad</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>