Skip to content

Tkinter iconphoto method causing memory leak? #157020

Description

@om-prod

Bug report

Bug description:

Hello, I am new to creating issues (and an immature programmer; been coding for years but I ain't like a god type of programmer) so I hope that I can be clear as possible.

This project has been in production for about a month now but I stopped because of the memory leak which at first thought was about my
bad logic in each tabs (My program is centered on being an offline MAL, though yet to fully plan out its total use) wherein I fixed it;
The problem still occurs. (This program uses 10mb+ of memory and doesn't clear it out)

Right now, I am in the middle of creating another program in python using Tkinter for my GUI. I, then found out that it was not taking
up memory like my other project, and that pulled me into testing the other project to try and find the main issue. The first thing I looked
at was the compressed images (I found an image compression technique that allows the integration of image inside the code with base64). It wasn't; I removed the importation of my other python file and stopped calling the StartUpPage class which didn't fix anything. Now, I am looking at a naked Main class:

from configs import Images as img
import tkinter as tk

import tabs < This is removed

class Main:
	def __init__(self):
		window = tk.Tk()
		
		icon = tk.PhotoImage(data=img.icon.value)
		window.title("Basic Media Stashing")
		window.resizable(False, False)
		window.iconphoto(True ,icon)
		window.config(bg="white")		

		tabs.StartUpPage(window) < This is removed
		
		window.mainloop()
if __name__ == "__main__":
	. . . Main() < No problem here just a runtime logic

After, clearing out the other file and the calling of the start-up page. I, then checked the other way of data being created: The PhotoImage.
I already knew that there was some sort of problem with the PhotoImage but to spare you the hour of head scratching it wasn't it.

And then, finally, I removed the one using the icon: The IconPhoto method.. and it was the problem. I tried making that default arg to
False as it was; it made it 14mb+ memory without clearing out. I tried finding an issue on this particular method but I found none.

Is this problem new and can anyone help me fix this? Is this soley Tkinter or does python's garbage collection have a problem as well?

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-tkintertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions