title: Memory leak when embedding python into my application
body: <p>The following program, when linked against python 2.7.13 and run on Windows 10 slowly but steadily leaks memory.</p>
  
  <pre><code>#include &lt;Python.h&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      std::cout &lt;&lt; "Python version: " &lt;&lt; PY_VERSION &lt;&lt; std::endl;
  
      while (true)
      {
          Py_Initialize();
          //PyGC_Collect();
          Py_Finalize();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The interesting fact is that it seems not every iteration leaks memory. What I see, though, is that the reference count that python prints slowly increases by a (non-constant) count of approximately 90 per iteration regardless of the leak. Using the Visual Studio Diagnostic Tools I figured out that the leak is coming from a call to <code>PyImport_ImportModule()</code> when it reads a compiled module from disk (the actual call stack is several levels deep).</p>
  
  <p>Are any additional cleanup steps necessary that I am not aware of? Or is there something about the Python garbage collector that might cause this and it is not a "real" memory leak?</p>