Following is my code:
from ab import Ab
class Xyz:
def __init__():
self.a = Ab.get_unique_instance()
This is how the get_unique_instance()
function is defined in ab.py
class Ab:
instance = []
def get_unique_instance():
if len(Ab.instance) == 0:
new_instance = Ab()
Ab.instance.append(new_instance)
return Ab.instance[0]
This is done to ensure only one instance of Ab is ever there. The problem is that the instance of Ab is still in memory even when the object created from class Xyz goes out of scope. How to delete this object explicitly?