This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tkinter memory leak on OS X
Type: resource usage Stage: resolved
Components: macOS, Tkinter Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: Mirano Tuk, ned.deily, ronaldoussoren
Priority: normal Keywords:

Created on 2016-07-16 08:59 by Mirano Tuk, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg270550 - (view) Author: Mirano Tuk (Mirano Tuk) Date: 2016-07-16 08:59
There seems to be a memory leak in tkinter on OSX (Windows and Linux don't seem to be affected). Explicitly calling Tk.update() sometimes permanently allocates a multiple of 4096 bytes. Allocation happens more frequently if update calls are in close succession.

import time
from tkinter import Tk
root = Tk()

while True:
    root.update()  # Huge memory leak

while True:
    root.update()  # No memory leaks
    time.sleep(1)

Issue occurs on python3.3 and above, did not test on older versions.
msg270571 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-07-16 15:55
tkinter is pretty much just a thin wrapper around the Tcl/Tk C API so suspicion for behavior like this should start there.  Usually, the easiest way to confirm that is to write an equivalent test in Tcl using its wish shell but, in this case, there's an even easier way.  The memory leak is easy to see if you use the badly out-of-date and seriously flawed system Tcl/Tk 8.5.x supplied by Apple in OS X releases since 10.6.  If tkinter is linked with an up-to-date Tcl/Tk, the leak should go away.  At least that's the case when using python3.5 from python.org 10.6+ installers and with ActiveTcl 8.5.18 installed.  See https://www.python.org/download/mac/tcltk/ for more info.
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71716
2016-07-16 15:55:57ned.deilysetmessages: - msg270570
2016-07-16 15:55:44ned.deilysetmessages: + msg270571
2016-07-16 15:55:01ned.deilysetstatus: open -> closed
versions: - Python 3.3, Python 3.4
messages: + msg270570

resolution: third party
stage: resolved
2016-07-16 08:59:54Mirano Tukcreate