If I were to run
class Myclass():
def __init__(self, value):
self.value = value
var1 = Myclass(1) # initializes the first instance of Myclass
var1 = Myclass(2) # initializes the second instance of Myclass
would the first instance of Myclass linger around in memory? Would the garbage collector (?) free up the space? Do I have to call del var1
to properly free the memory at runtime?
The background of my question is that I run a large loop where in every iteration I need a different instance of a specific class. While I call del
explicitly at the moment, it would be nice to know the default behaviour.