Pierre Lemerle
Pierre Lemerle

Reputation: 1

How to free the input argument of a class in its constructor?

I'd like to build a GUI for an OLED screen application. I've built one class per menu frame. In each class I need to manage screen updating and key events in a loop. When a certain key is pressed I create an instance of the next class corresponding to the next menu frame. But the instance of the current menu frame still exists.

Then how to free the instance of the calling class when creating the object of the next menu frame?

I tried do something like:

class Menu1():
    def __init__(self, a):
        self.a = a
        if a == 1:      
            menu = Menu2(self)
     
    def doIexist(self):
        print("yes")

class Menu2(): 
    def __init__(self, caller):
        del caller
        print("hello")

toto = Menu1(1)
toto.doIexist()

But it returns

hello
yes

Upvotes: -1

Views: 47

Answers (1)

bbd 666
bbd 666

Reputation: 13

From what I read in the comments, I just need to remove

del caller

and let python manage the memory with the garbage collector

Upvotes: 0

Related Questions