Detailed Description
Libcwd does a weak attempt to support debugging of memory leaks. I hope to greatly improve this in the future.It is possible to mark allocations that are done till that moment, and then later check for memory leaks by expecting no other memory allocations than those that already existed before the mark. This is done by creating a marker_ct object. The check for memory leaks is done when the marker is removed again. This can be done recursively.A
marker is created by passing it a description:
#if CWDEBUG_MARKER
#endif
Any allocation done
after the creation of this marker will be reported as a
leak at the moment the
marker is deleted.Markers are clearly visible in the Allocated memory Overview. They are labeled MARKER (see also the
allocator type table). All memory that is allocated after a
marker, is displayed indented and below that marker in the Allocated memory Overview.Finally, it is possible to move specific memory blocks outside markers, so they will not cause a memory leak detection. This is done with the function
which would move the memory allocation pointed to by
ptr outside the test region of
marker.A complete example program with output is given here:
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
class A {
int i;
int j;
char k;
};
int main(int argc, char* argv[])
{
A* a1 = new A;
#if CWDEBUG_MARKER
#endif
A* a2 = new A[10];
AllocTag(a2,
"Created after the marker");
int* p = new int[30];
AllocTag(p,
"Created after the marker");
#if CWDEBUG_MARKER
#endif
#if CWDEBUG_MARKER
delete marker;
#endif
#if CWDEBUG_ALLOC
#else
#endif
return 0;
}