title: How to fix "swig/python detected a memory leak of type 'HWND *', no destructor found"?
body: <p>Consider this mcve:</p>
  <p><strong>mcve.h</strong></p>
  <pre><code>#pragma once
  
  #include &lt;windows.h&gt;
  
  class Windows {
    public:
      static HWND GetActiveWindow();
      static HWND GetForegroundWindow();
  };
  </code></pre>
  <p><strong>mcve.cpp</strong></p>
  <pre><code>#include &quot;mcve.h&quot;
  
  HWND Windows::GetActiveWindow() {
      return ::GetActiveWindow();
  }
  HWND Windows::GetForegroundWindow() {
      return ::GetForegroundWindow();
  }
  </code></pre>
  <p><strong>mcve.i</strong></p>
  <pre><code>%module mcve
  
  %include &lt;std_string.i&gt;
  %include &lt;std_vector.i&gt;
  %include &lt;typemaps.i&gt;
  %include &lt;windows.i&gt;
  %include &lt;cpointer.i&gt;
  %include &lt;carrays.i&gt;
  
  %{
  #include &quot;mcve.h&quot;
  %}
  
  
  %include &quot;mcve.h&quot;
  </code></pre>
  <p><strong>setup.py</strong></p>
  <pre><code>from distutils.core import Extension
  from distutils.core import setup
  
  setup(
      name=&quot;mcve&quot;,
      ext_modules=[
          Extension(
              &quot;_mcve&quot;,
              sources=[&quot;mcve.i&quot;, &quot;mcve.cpp&quot;, &quot;mcve_wrap.cpp&quot;],
              swig_opts=[&quot;-c++&quot;, &quot;-python&quot;],
              include_dirs=[&quot;.&quot;],
              library_dirs=[
                &quot;D:/software/vcpkg/installed/x86-windows/lib&quot;
              ],
              libraries=[&quot;user32&quot;]
          )
      ],
      py_modules=[&quot;mcve&quot;],
  )
  </code></pre>
  <p>In order to run it, make sure you adjust properly the <code>library_dirs</code> variable and then just type:</p>
  <pre><code>python setup.py build_ext --inplace
  </code></pre>
  <p>If the extension has been generated succesfully then you just run <code>python test.py</code> and you should see an output similar to this:</p>
  <pre><code>&gt;python test.py
  swig/python detected a memory leak of type 'HWND *', no destructor found.
  swig/python detected a memory leak of type 'HWND *', no destructor found.
  </code></pre>
  <p>I know you can use swig <code>-nodefaultdtor</code> to not generate implicit default destructors, I've tried and that didn't make any difference.</p>
  <p>For the sake of completeness, here's roughly how the HWND typedefs would look like:</p>
  <pre><code>typedef PVOID HANDLE;
  typedef HANDLE HWND;
  typedef void *PVOID;
  </code></pre>
  <p><strong>QUESTION:</strong> What's the proper way in swig to prevent that memory leak of HWND?</p>