We are using the pimpl idiom in our classes. The pimpl struct is declared in the class which contains the pimpl pointer like so:
struct MyClassImpl;
friend struct MyClassImpl;
boost::scoped_ptr<MyClassImpl> m_Impl;
The implementation for the pimpl is in a seperate file called MyClassImpl.cpp For example:
struct MyClass::MyClassImpl
{
QString m_Name;
int m_Type;
double m_Frequency;
int m_DefaultSize;
QVariant m_DefaultValue;
boost::shared_ptr<SomeOtherClass> m_SomeOtherClass;
~MyClassImpl()
{
}
};
In the constructor of a class that contains a pimpl pointer, I would have in the member variable initialization list something like
m_Impl(new MyClassImpl())
Now, we have enabled memory leak detection in our source code like so:
// Memory leaks detection in Visual Studio
#if defined (_WIN32) && defined (_DEBUG)
# define _CRTDBG_MAP_ALLOC
# include <crtdbg.h>
# define new new(_NORMAL_BLOCK ,__FILE__, __LINE__)
#endif
I am finding that when the program exits, memory leaks are reported for the MyClassImpl() struct m_Impl(new MyClassImpl()):
..\..\src\MyClass.cpp(29) : {290222} normal block at 0x0B9664E0, 48 bytes long.
Data: <X l V Y@> 58 1C 6C 03 56 00 00 00 00 00 00 00 00 00 59 40
I don't understand why since the m_Impl is a boost::scoped_ptr and the QString, QVariant, and shared_ptr are all managed. Any ideas?