Open
Description
Bug report
Bug description:
Minimal-ish reproducible example:
import tkinter as tk
from itertools import cycle
root = tk.Tk()
# Any GIF should work
gif_path = r""
frames = []
for i in range(100):
try:
# Using PIL and ImageTk has no difference
gif = tk.PhotoImage(file=gif_path, format=f'gif -index {i}')
frames.append(gif.subsample(1, 1).copy())
except tk.TclError:
break
label = tk.Label(root)
label.pack()
frame_cycle = cycle(frames)
def update_frame():
frame = next(frame_cycle)
label.config(image=frame)
# Happens with other update times however more updates = faster memory leak
root.after(1, update_frame)
root.after(0, update_frame)
root.mainloop()
While the leak is most noticeable when updating a label it also happens when scrolling a text widget with labels that have images
Recording.2024-09-23.203110.mp4
Here it is increasing just by scrolling over the paused gifs (static images)
Recording.2024-09-23.203836.mp4
Note that the recording is filmed at much lower fps, appearing slower than it is
I was unable to narrow the leak down, tracemalloc didn't show anything of use (possibly an issue in tcl/tk?)
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux, Windows