title: Py_INCREF/DECREF: When
body: <p>Is one correct in stating the following:</p>
  
  <ol>
  <li><p>If a Python object is created in a C function, but the function doesn't return it, no <code>INCREF</code> is needed, but a <code>DECREF</code> is.</p></li>
  <li><p>[false]If the function does return it, you do need to <code>INCREF</code>, in the function that receives the return value.[/false]</p></li>
  <li><p>When assigning C typed variables as attributes, like <code>double</code>, <code>int</code> etc., to the Python object, no <code>INCREF</code> or <code>DECREF</code> is needed.</p></li>
  <li><p>Is the following safe to use? Assigning Python objects as attributes to your other Python objects goes like this:</p>
  
  <pre><code>PyObject *foo;
  foo = bar;  // A Python object
  tmp = self-&gt;foo;
  Py_INCREF(foo);
  self-&gt;foo = foo;
  Py_XDECREF(tmp);
  // taken from the manual, but it is unclear if this works in every situation
  </code></pre></li>
  <li><p>Deallocation of a Python object needs to <code>DECREF</code> for every other Python object that it has as an attribute, but not for attributes that are C types.</p></li>
  </ol>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>With regards to 'C type as an attribute', I mean bar and baz:</p>
  
  <pre><code>typedef struct {
      PyObject_HEAD
      PyObject *foo;
      int bar;
      double baz;
  } FooBarBaz;
  </code></pre>