Note that there are some explanatory texts on larger screens.

plurals
  1. POpimpl idiom struct memory leak
    primarykey
    data
    text
    <p>We are using the pimpl idiom in our classes. The pimpl struct is declared in the class which contains the pimpl pointer like so:</p> <pre><code>struct MyClassImpl; friend struct MyClassImpl; boost::scoped_ptr&lt;MyClassImpl&gt; m_Impl; </code></pre> <p>The implementation for the pimpl is in a seperate file called MyClassImpl.cpp For example:</p> <pre><code> struct MyClass::MyClassImpl { QString m_Name; int m_Type; double m_Frequency; int m_DefaultSize; QVariant m_DefaultValue; boost::shared_ptr&lt;SomeOtherClass&gt; m_SomeOtherClass; ~MyClassImpl() { } }; </code></pre> <p>In the constructor of a class that contains a pimpl pointer, I would have in the member variable initialization list something like</p> <pre><code>m_Impl(new MyClassImpl()) </code></pre> <p>Now, we have enabled memory leak detection in our source code like so:</p> <pre><code>// Memory leaks detection in Visual Studio #if defined (_WIN32) &amp;&amp; defined (_DEBUG) # define _CRTDBG_MAP_ALLOC # include &lt;crtdbg.h&gt; # define new new(_NORMAL_BLOCK ,__FILE__, __LINE__) #endif </code></pre> <p>I am finding that when the program exits, memory leaks are reported for the MyClassImpl() struct m_Impl(new MyClassImpl()):</p> <pre><code>..\..\src\MyClass.cpp(29) : {290222} normal block at 0x0B9664E0, 48 bytes long. Data: &lt;X l V Y@&gt; 58 1C 6C 03 56 00 00 00 00 00 00 00 00 00 59 40 </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload