lines 8-109 of file: include/cppad/utility/memory_leak.hpp

{xrst_begin memory_leak app}
{xrst_spell
   inuse
   statics
}

Memory Leak Detection
#####################

Deprecated 2012-04-06
*********************
This routine has been deprecated.
You should instead use the routine :ref:`ta_free_all-name` .

Syntax
******

| # ``include <cppad/utility/memory_leak.hpp>``
| ``flag`` = ``memory_leak`` ()

*flag* = *memory_leak* ( *add_static* )

Purpose
*******
This routine checks that the are no memory leaks
caused by improper use of :ref:`thread_alloc-name` memory allocator.
The deprecated memory allocator :ref:`track_new_del-name` is also checked.
Memory errors in the deprecated :ref:`omp_alloc-name` allocator are
reported as being in ``thread_alloc`` .

thread
******
It is assumed that :ref:`in_parallel()<ta_in_parallel-name>` is false
and :ref:`thread_num<ta_thread_num-name>` is zero when
``memory_leak`` is called.

add_static
**********
This argument has prototype

   ``size_t`` *add_static*

and its default value is zero.
Static variables hold onto memory forever.
If the argument *add_static* is present (and non-zero),
``memory_leak`` adds this amount of memory to the
:ref:`inuse<ta_inuse-name>` sum that corresponds to
static variables in the program.
A call with *add_static* should be make after
a routine that has static variables which
use :ref:`get_memory<ta_get_memory-name>` to allocate memory.
The value of *add_static* should be the difference of

   ``thread_alloc::inuse`` (0)

before and after the call.
Since multiple statics may be allocated in different places in the program,
it is expected that there will be multiple calls
that use this option.

flag
****
The return value *flag* has prototype

   ``bool`` *flag*

If *add_static* is non-zero,
the return value for ``memory_leak`` is false.
Otherwise, the return value for ``memory_leak`` should be false
(indicating that the only allocated memory corresponds to static variables).

inuse
*****
It is assumed that, when ``memory_leak`` is called,
there should not be any memory
:ref:`inuse<ta_inuse-name>` or :ref:`omp_inuse-name` for any thread
(except for inuse memory corresponding to static variables).
If there is, a message is printed and ``memory_leak`` returns false.

available
*********
It is assumed that, when ``memory_leak`` is called,
there should not be any memory
:ref:`available<ta_available-name>` or :ref:`omp_available-name` for any thread;
i.e., it all has been returned to the system.
If there is memory still available for any thread,
``memory_leak`` returns false.

TRACK_COUNT
***********
It is assumed that, when ``memory_leak`` is called,
:ref:`track_new_del@TrackCount` will return a zero value.
If it returns a non-zero value,
``memory_leak`` returns false.

Error Message
*************
If this is the first call to ``memory_leak`` , no message is printed.
Otherwise, if it returns true, an error message is printed
to standard output describing the memory leak that was detected.

{xrst_end memory_leak}
