Re: memory leak detection techniques
"Norbert Unterberg" <nunterberg@newsgroups.nospam> wrote in message
news:uX9Wym4CIHA.748@TK2MSFTNGP04.phx.gbl...
If the memory leak is associated with CMyThing's copy constructor then I
guess it contains some deep copy opearions?
Not particularly deep...
If you overrode the CMyThing's copy constructor, did you also override
it's assignment operator and destructor? See the "Law of the Big Three".
http://www.artima.com/cppsource/bigtwo.html
.... and yes - I am particular to the point of pedantry about that sort of
thing.
But explaining the problem has given me an idea.
Here's some real code:
=========================
#ifdef MZW32N_EXPORTS
#define MZWN_API __declspec(dllexport)
#define EXTERN_MZWN_API
#else
#define MZWN_API __declspec(dllimport)
#define EXTERN_MZWN_API extern
#endif
#include "percussion.h"
#include <vector>
#pragma warning( disable: 4251 ) // These are annoying.
#pragma warning( disable: 4231 ) // MSDN article Q168958 tells me to ignore
this warning.
// Instantiate a vector:
// This seems to be necessary if the class derived from vector is to be
exported.
EXTERN_MZWN_API template class MZWN_API
std::allocator<CPercussionInstrument>;
EXTERN_MZWN_API template class MZWN_API std::vector<CPercussionInstrument>;
// class CPercussionSet
class MZWN_API CPercussionSet : public std::vector<CPercussionInstrument>
{
public:
CPercussionSet();
CPercussionSet( const CPercussionSet &ps );
virtual ~CPercussionSet();
CPercussionSet & operator = ( const CPercussionSet &ps );
//....
};
=============
I am pretty sure the copy constructor, destructor, and assignment of
CPercussionInstrument are ok (I am checking). I *am* a little concerned
about exporting this class from the DLL, (in which the only instance is
global) and wondering if that is at the root of things. It may not be
being correctly destroyed when the DLL is unloaded - though the destructor
*is* getting called.
Perhaps I should store a global; pointer to a CPercussionSet and explicitly
create and destroy it with new and delete. That way I'd have more control
over when it happens! I'll experiment.
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