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: Memory leak in Tkinter
Type: resource usage Stage: resolved
Components: Tkinter Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dtalkin, miss-islington, serhiy.storchaka, vstinner, xtreak
Priority: normal Keywords: patch

Created on 2018-09-24 21:30 by dtalkin, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
leak_demo.py dtalkin, 2018-09-25 14:24
leak_demo2.py serhiy.storchaka, 2018-10-21 11:56
Pull Requests
URL Status Linked Edit
PR 9559 closed serhiy.storchaka, 2018-09-25 08:07
PR 10025 merged serhiy.storchaka, 2018-10-21 11:57
PR 10069 merged miss-islington, 2018-10-23 19:41
PR 10070 merged miss-islington, 2018-10-23 19:41
PR 10181 merged serhiy.storchaka, 2018-10-28 16:50
Messages (8)
msg326289 - (view) Author: David Talkin (dtalkin) Date: 2018-09-24 21:30
The Tkinter.PhotoImage class leaks memory with each change of the 'data' Attribute due to Image calling tk._createbytearray, which allocates memory, but never frees it.

The offending method is in the TkApp class, _createbytearray().
msg326327 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-25 06:55
Thanks for the report David. Feel free to attach reproducible script if any that might trigger this. I am adding Serhiy who might have a better understanding of this. Relevant issue where _createbytearray was added : issue21580 .
msg326355 - (view) Author: David Talkin (dtalkin) Date: 2018-09-25 14:24
Attached please find a Python script that demonstrates the bug.

David

On Tue, Sep 25, 2018 at 2:55 AM Karthikeyan Singaravelan <
report@bugs.python.org> wrote:

>
> Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:
>
> Thanks for the report David. Feel free to attach reproducible script if
> any that might trigger this. I am adding Serhiy who might have a better
> understanding of this. Relevant issue where _createbytearray was added :
> issue21580 .
>
> ----------
> nosy: +serhiy.storchaka, xtreak
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue34794>
> _______________________________________
>
msg328205 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-21 11:56
Here is a simpler reproducer.

Actually the problem was not in _createbytearray(), but in converting the Python wrapper around Tcl_Obj into Tcl_Obj. _createbytearray() just exposed it. The leak exists in Python 3 too, but it is hard to reproduce it.
msg328338 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-23 19:40
New changeset df13df41a25765d8a39a77220691698498e758d4 by Serhiy Storchaka in branch 'master':
bpo-34794: Fix a leak in Tkinter. (GH-10025)
https://github.com/python/cpython/commit/df13df41a25765d8a39a77220691698498e758d4
msg328342 - (view) Author: miss-islington (miss-islington) Date: 2018-10-23 20:25
New changeset 2c549250d8fd6755e3338a771d250e34c78bdb50 by Miss Islington (bot) in branch '3.6':
bpo-34794: Fix a leak in Tkinter. (GH-10025)
https://github.com/python/cpython/commit/2c549250d8fd6755e3338a771d250e34c78bdb50
msg328347 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-10-23 21:46
New changeset f7cefb427cbc50d89a4f19f7f334a4f5421cefd3 by Victor Stinner (Miss Islington (bot)) in branch '3.7':
bpo-34794: Fix a leak in Tkinter. (GH-10025) (GH-10069)
https://github.com/python/cpython/commit/f7cefb427cbc50d89a4f19f7f334a4f5421cefd3
msg328715 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-28 17:36
New changeset aaea2802da0a074c695ab86911d8bcc0b2dd5ec5 by Serhiy Storchaka in branch '2.7':
[2.7] bpo-34794: Fix a leak in Tkinter. (GH-10025) (GH-10181)
https://github.com/python/cpython/commit/aaea2802da0a074c695ab86911d8bcc0b2dd5ec5
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 78975
2018-10-28 19:14:46serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-28 17:36:06serhiy.storchakasetmessages: + msg328715
2018-10-28 16:50:30serhiy.storchakasetpull_requests: + pull_request9504
2018-10-23 21:46:43vstinnersetnosy: + vstinner
messages: + msg328347
2018-10-23 20:25:57miss-islingtonsetnosy: + miss-islington
messages: + msg328342
2018-10-23 19:41:18miss-islingtonsetpull_requests: + pull_request9403
2018-10-23 19:41:10miss-islingtonsetpull_requests: + pull_request9402
2018-10-23 19:40:58serhiy.storchakasetmessages: + msg328338
2018-10-21 12:05:09serhiy.storchakasettitle: memory leak in TkApp:_createbytearray -> Memory leak in Tkinter
2018-10-21 11:57:08serhiy.storchakasetpull_requests: + pull_request9364
2018-10-21 11:56:54serhiy.storchakasetfiles: + leak_demo2.py

messages: + msg328205
versions: + Python 3.6, Python 3.7, Python 3.8
2018-09-25 14:24:46dtalkinsetfiles: + leak_demo.py

messages: + msg326355
2018-09-25 08:07:04serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request8961
2018-09-25 06:55:24xtreaksetnosy: + serhiy.storchaka, xtreak
messages: + msg326327
2018-09-24 21:30:12dtalkincreate