Member 11545824 wrote:
how can check the rest of your program for non-GDI memory leaks, if i don't know how? :(
One way is to replace operators new(), delete(), etc. with operators that log memory allocations. For example, an pseudo-code implementation of new() and delete() could look like this:
std::map< void*, std::size_t > allocations;
void* operator new( std::size_t size )
{
void* p = std::malloc( size );
if ( p != nullptr )
{
allocations.insert( make_pair( p, size ) );
return p;
}
throw std::bad_alloc();
}
void operator delete( void* p )
{
if ( allocations.find( p ) == allocations.end() )
{
// handle case of deallocation of unallocated memory
}
std::free( p );
allocations.erase( allocations.find( p ) );
}
Note that the code will probably not compile; I just wrote it quickly as an example. An additional function, called when your program exits, can ensure that the allocations map is empty. If it is not, the size(s) of the blocks may give you an idea as to what blocks were not freed.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill