I am working on a text adventure game written in Python just for fun (to see if I could do it). I am working on the module for the entities, and am working on a method for them being killed. When an entity is killed, instead of just displaying a kill message and rendering the entity unable to act, I also want its instance to be deleted to conserve memory.
How can I make an instance of the entity class delete itself?
For example (partly pseudocode):
class Entity(object):
#other methods here
def kill(self):
if self.health <= 0:
self.deleteinstance
or
deleteinstance(self)
Thank you in advance for your help.
EDIT: I understand that this is a duplicate, but the answers in all the others reference that objects are deleted when nothing refers to them. My question here is how to make nothing refer to the instance of this class, because without a kill
method, presumably the instance will still be in memory with negative health.