title: how to prevent Python garbage collection for anonymous objects?
body: <p>In this Python code</p>
  
  <pre><code>import gc
  gc.disable()
  &lt;some code ...&gt;
  MyClass()
  &lt;more code...&gt;
  </code></pre>
  
  <p>I am hoping that the anonymous object created by <code>MyClass</code> constructor would not be garbage-collected.  <code>MyClass</code> actually links to a shared object library of C++ code, and there through raw memory pointers I am able to inspect the contents of the anonymous object. </p>
  
  <p>I can then see that the object is immediately corrupted (garbage collected).  </p>
  
  <p>How to prevent Python garbage collection for everything?</p>
  
  <p>I have to keep this call anonymous.  I cannot change the part of the code <code>MyClass()</code> - it has to be kept as is.   </p>
  
  <p><code>MyClass()</code> has to be kept as is, because it is an exact translation from C++ (by way of SWIG) and the two should be identical for the benefit of people who translate.   </p>
  
  <p>I have to prevent the garbage collection by some "initialization code", that is only called once at the beginning of the program.  I cannot touch anything after that.  </p>