我想知道这里发生了什么。当我运行该程序时,我注意到即使已销毁并删除了对它的任何引用,TestFrame类的内存(大约200mb)仍在使用中。
import tkinter as tk
import tkinter.ttk as ttk
class TestFrame(ttk.Frame):
def __init__(self, master):
super().__init__(master)
self.bigDictionary = {'Hello World' + str(num): 'Hello World' + str(num) for num in range(1000000)}
self.testLabel = ttk.Label(self, text='This is a test Label')
self.testLabel.grid()
root = tk.Tk()
testFrame = TestFrame(root)
testFrame.grid()
testFrame.destroy()
testFrame = ''
root.mainloop()
然后我将标签从属性中删除,如下所示:
def __init__(self, master):
super().__init__(master)
self.bigDictionary = {'Hello World' + str(num): 'Hello World' + str(num) for num in range(1000000)}
testLabel = ttk.Label(self, text='This is a test Label')
testLabel.grid()
现在,当我运行这段代码时,我注意到Python不再从框架中保留内存。任何人都可以对这里发生的事情提供一些见识吗?