Memory Leaks

On the way home tonight I came up with a method of memory leak detection. The problem with memory leak detection, is if you have objects still active, your list of unallocated memory can be quite big, and if its a small leak, it can take a long time to track down. So as well as storing the filename and line number, I thought, why not store the “this” pointer for objects.

Now when allocation happens again on the same line number and filename, if there is an allocation for the current “this” object matching these, then allocation is happening again on the same object.

There is a problem with this however, loops that allocate will flag as reallocation without deallocation. These can be ignored though if care is taken with the objects that are doing this.