title: Delete an object and all references to it in Python?
body: <p>Is there a way to remove all references to an object at once? I know that's unpythonic, so I'll explain what I'm trying to do and maybe someone knows a better way.</p>
  
  <p>I'm writing an object-oriented wrapper around a SWIG wrapper for a C library. When a proxy for one of the C objects is deleted, it also deletes child objects (directly in C). I'd like that to also trigger deletion of their proxy objects in Python. Otherwise I run into a situation where there are Python objects carrying around invalid pointers which will segfault if they're accessed.</p>
  
  <p>It looks sort of like this:</p>
  
  <pre><code>class Parent(object):
      def __init__(self):
          self.ptr = swig.createParent()
      def __del__(self):
          swig.deleteParent(self.ptr) # also deletes children
  
  class Child(object):
      def __init__(self, parent):
          self.ptr = swig.createChild(parent)
      def __del__(self):
          swig.deleteChild(self.ptr)
  </code></pre>
  
  <p>And this is the situation I'm worried about:</p>
  
  <pre><code>p = Parent()
  c = Child(parent)
  del p
  # accessing c.ptr now would be bad right?
  </code></pre>