title: When are python classes and class attributes garbage collected?
body: <pre><code>class Member(object):
      def __init__(self, identifier):
          self.identifier = identifier
          print "Member __init__", self.identifier
  
      def __del__(self):
          print "Member __del__", self.identifier
          with open("/home/might/" + self.identifier, "w") as outF:
              outF.write(self.identifier)
  
  class WithMembers(object):
      def __init__(self):
          print "WithMembers __init__"
          print WithMembers.classMem
          self.instanceMem = Member("instance mem")
  
      def __del__(self):
          print "WithMembers __del__"
  
      classMem = Member("class mem")
  
  if __name__ == "__main__":
      print "main"
      WithMembers()
      #del WithMembers.classMem       # "Member __del__ class mem" before "end"
      #del WithMembers                # "Member __del__ class mem" after "end"
      print "end"
  </code></pre>
  
  <p>The above code is in Hidden.py and running <code>python Hidden.py</code> produces the following output:</p>
  
  <pre><code>Member __init__ class mem
  main
  WithMembers __init__
  &lt;__main__.Member object at 0x935aeec&gt;
  Member __init__ instance mem
  WithMembers __del__
  Member __del__ instance mem
  end
  </code></pre>
  
  <p>I don't see <code>Member __del__ class mem</code> in output or the <code>class mem</code> file unless I un-comment one of the <code>del</code> statements. Why is this? When are python classes and class attributes garbage collected?</p>