How to delete every reference of an object in Python?

No no no. Python has a garbage collector that has very strong territory issues – it won’t mess with you creating objects, you don’t mess with it deleting objects.

Simply put, it can’t be done, and for a good reason.

If, for instance, your need comes from cases of, say, caching algorithms that keep references, but should not prevent data from being garbage collected once no one is using it, you might want to take a look at weakref.

Leave a Comment