Re: memory leak detection techniques
"Norbert Unterberg" <nunterberg@newsgroups.nospam> wrote in message
news:eTA3i72CIHA.4952@TK2MSFTNGP02.phx.gbl...
How do you know about the leak? Do you see the memory leak dump in the
IDE's
output window when your application exits?
Yes.
If yes then you have a good chance. You can set a memory breakpoint on the
allocation ID that is listed in the memory leaks dump. Add a call to
_CrtSetBreakAlloc(<put the ID here>); at the beginning of main()
Thank you! I have never needed that before. I now know where the leak
is, but not why.
But the plot thickens:
In my non-MFC DLL I have a global instance of an object of the form
CMyCollection : public std::vector<CMyThing>;
Its normal constructor is called on startup, which just creates and empty
collection.
It is only called once.
It is filled in (also once) with a method of CMyColllection schematically of
the form
CMyCollection::FillIn()
{
CMyThing thing;
for( allthings )
{
thing = .... // fill in the thing
push_back( thing ); //*********
}
}
It is usually not changed, and lasts until the program shuts down.
It is never copied. (It has a copy constructor, because I feel nervous
without them, but it is never called.)
The destructor is called once, and just calls clear() (because I feel it
is neat to do so).
I am being told that the memory leak is associated with the CMyThing's copy
constructor invoked by push_back() above.
How can that be?
Even stranger, I have had all of this present in the code for years and a
memory leak has only been reported recently.
Any ideas gratefully received.
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm