title: python nested function memory leak?
body: <p>from a previous experience in java, I am aware that if two GUI class objects contain member variable references of each other, there can be a memory leak until both objects are destroyed.</p>
  
  <p>That situation was very messy to debug and so I want to work with strict guidelines to avoid memory leaks now in python.</p>
  
  <p>I currently have a GUI system where there is a main window (parent_window) and many sub windows (child windows) that pop up with ancillary options for the user, etc.</p>
  
  <p>I thought an easy way to prevent memory leaks is don't keep a class member variable of the parent window in all of the child windows.</p>
  
  <pre><code>class child_window(object):
      def make_child_window(self, parent_window):
          def on_ok(): parent_window.show()
          QtCore.QObject.connect(self.okbutton, QtCore.SIGNAL("clicked()"), on_ok)
  </code></pre>
  
  <p>as you can see, I have a nested function that calls the parent_window which is contained only in the local scope of the class method ("make_child_window"). Is this cheating? On a lower level does python essentially store my "parent_window" as a class variable? What are your other recommendations for isolating the child_window from holding onto the parent_window in memory? </p>