title: Will my Tkinter popupWindow class and function have all of its variables garbage collected once the function ends?
body: <p>New programmer here starting to dive into Tkinter. I had a question regarding a popup window class I created in Tkinter. I wanted to make sure that each time I call the popupWindow in my tkinter UI I’m not creating new variables that NEVER get garbage collected, resulting in memory issues after a couple hundred button presses. (In a different part of my code, I had an issue beforehand with variables not getting garbage collected resulting in my program locking up after sometime.)</p>
  
  <p>Example code below shows a popupWindow class, a popup window function that calls the class, and then a build function that dynamically creates a data table and refreshes(rebuilds) it using the .after method every 30 seconds. I believe that all variables regarding the popupWindow should be garbage collected since they exist within the popup function. Please correct me if I’m wrong and you think that not all the variables of the popupWindow will be garbage collected. If you have any other comments or adjustments regarding my example code feel free to add!</p>
  
  <p>Thank you in advance!</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  from tkinter import *
  
  root = Tk()
  root.configure(background='black')
  
  
  class popupWindow(Toplevel):
      def __init__(self,master):
          top=self.top=Toplevel(master)
          self.l=Label(top,text='Test Button')
          self.l.pack()
          self.e=Entry(top)
          self.e.pack()
          self.b=Button(top,text='Ok',command=self.cleanup)
          self.b.pack()
      def cleanup(self):
          self.value=self.e.get()
          self.top.destroy()
          return self.value
  
  def popup(event):
          w=popupWindow(root)
          root.wait_window(w.top)
          print(w.value)
  
  
  def build():
      mydf = pd.DataFrame([np.arange(1, np.random.randint(3, 7)) * np.random.randint(1,10) for x in np.arange(1, np.random.randint(3, 7))])
  
      for label in root.grid_slaves():
          label.destroy()
  
      rowindex = 1
      for row in mydf.iterrows():
          colindex = 1
          for i in row[1]:
              label = Label(root, text=str(i), width=7)
              label.bind('&lt;Button-1&gt;', popup)
              label.grid(row=rowindex,column=colindex)
              colindex += 1
          rowindex += 1
  
  def refresh():
      build()
      root.after(30000, refresh)
  
  refresh()
  root.mainloop()
  </code></pre>