Python uses garbage collection to manager memory, which means you do not have to delete anything. This class is fine:
class Bond():
def breakBond(self):
self.start.removeBond(self)
self.end.removeBond(self)
note that del
does not delete anything from memory! It simply removes a reference to an object, but objects can have more than one reference:
>>> some_list = [1,2,3]
>>> b = some_list
>>> del b # destroys the list?
>>> b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> some_list # list is still there!
[1, 2, 3]
>>> c = some_list
>>> del some_list
>>> c # list is still there!
[1, 2, 3]
>>> del c
After the last del c
the interpreter can deallocate the list. In CPython the deallocation will be done immediately (in this simple case), however in other implementation of the language the interpreter might not deallocate the list immediately.
Also note that __del__
's documentation cites this fact. Furthermore it is a really low-level method which you don't need 99.9% of the time, so it certainly isn't the right way to handle your situation.