A class is defined like this:
class IterRegistry(type):
def __iter__(cls):
return iter(cls._registry)
class Example:
__metaclass__ = IterRegistry
_registry =[]
def __init__(self,iD):
self.iD = iD
self.count = 40
self._registry.append(self)
def reduceCount(self):
self.count -= 1
Over the course of the program more and more instances of the class are created. I have an timer running, which then runs a for Loop over all the instances and reduces the count by 1 for each.
def timer():
for i in Example:
i.reduceCount()
if i.count < 0:
#then delete the instance
My question is how do I delete this instance?
delas suggested in the Answer below, by setting the variable that references it toNoneor if it's inside a container (list, set, dict, ...) by removing it from there. (This assumes that no other variables are referencing this object, you can't force the deletion of an object that is still being referenced)