title: Why set a bound method to python object create a circular reference?
body: <p>I'm working in Python 2.7 and I fond that issue that puzzling me.</p>
  
  <p>That is the simplest example:</p>
  
  <pre><code>&gt;&gt;&gt; class A(object):
      def __del__(self):
          print("DEL")
      def a(self):
          pass
  
  &gt;&gt;&gt; a = A()
  &gt;&gt;&gt; del a
  DEL
  </code></pre>
  
  <p>That is OK like expected... now I'm trying to change the <code>a()</code> method of object <code>a</code> and what happen is that after change it I can't delete <code>a</code> any more:</p>
  
  <pre><code>&gt;&gt;&gt; a = A()
  &gt;&gt;&gt; a.a = a.a
  &gt;&gt;&gt; del a
  </code></pre>
  
  <p>Just to do some checks I've print the <code>a.a</code> reference before and after the assignment</p>
  
  <pre><code>&gt;&gt;&gt; a = A()
  &gt;&gt;&gt; print a.a
  &lt;bound method A.a of &lt;__main__.A object at 0xe86110&gt;&gt;
  &gt;&gt;&gt; a.a = a.a
  &gt;&gt;&gt; print a.a
  &lt;bound method A.a of &lt;__main__.A object at 0xe86110&gt;&gt;
  </code></pre>
  
  <p>Finally I used <code>objgraph</code> module to try to understand why the object is not released:</p>
  
  <pre><code>&gt;&gt;&gt; b = A()
  &gt;&gt;&gt; import objgraph
  &gt;&gt;&gt; objgraph.show_backrefs([b], filename='pre-backref-graph.png')
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xi6Qv.png" alt="pre-backref-graph.png"></p>
  
  <pre><code>&gt;&gt;&gt; b.a = b.a
  &gt;&gt;&gt; objgraph.show_backrefs([b], filename='post-backref-graph.png')
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/uhy9C.png" alt="post-backref-graph.png"></p>
  
  <p>As you can see in the <code>post-backref-graph.png</code> image there is a <code>__self__</code> references in b that have no sense for me because the self references of instance method should be ignored (as was before the assignment).</p>
  
  <p>Somebody can explain why that behaviour and how can I work around it?</p>