classification
Title: Memory use increase in function _tkinter._flatten
Type: resource usage Stage: resolved
Components: Extension Modules Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Stardust1225, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-07-12 07:00 by Stardust1225, last changed 2021-07-14 05:47 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27107 merged serhiy.storchaka, 2021-07-13 06:03
PR 27133 merged miss-islington, 2021-07-14 05:19
PR 27134 merged miss-islington, 2021-07-14 05:19
Messages (5)
msg397287 - (view) Author: stardust222 (Stardust1225) Date: 2021-07-12 07:00
In the following code, the memory use of function _tkinter._flatten is increase as the number of calls when I input an illegal value.


import sys
import tracemalloc
import _tkinter

arg_list = []
arg_list.append('ptqiioaaejhdoat')

# check for memory usage
memory_recorder = []
tracemalloc.start()
start_snapshot = tracemalloc.take_snapshot()
for i in range(0, 100):
  try:
    _tkinter._flatten(arg_list[0])
  except:
    pass
  if i % 10 == 0:
    one_snapshot = tracemalloc.take_snapshot()
    memory_recorder.append(one_snapshot.compare_to(start_snapshot, 'lineno')[0])

for i in range(2, len(memory_recorder)):
  if str(memory_recorder[i].traceback) == str(memory_recorder[1].traceback):
    print(memory_recorder[i].traceback)
    print(memory_recorder[i].size)

tracemalloc.stop()

And the output on my machine is 
test.py:19
3248
test.py:19
4800
test.py:19
6448
test.py:19
8000
test.py:19
9648
test.py:19
11248
test.py:19
12848
test.py:19
14400
msg397383 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-13 06:06
Thank you for your report stardust222. Indeed, there is a leak if an argument is a sequence or set, but not list or tuple. PR 27107 fixes it.
msg397465 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-14 05:19
New changeset f572cbf1faab33d9afbbe3e95738ed6fbe6e48e6 by Serhiy Storchaka in branch 'main':
bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107)
https://github.com/python/cpython/commit/f572cbf1faab33d9afbbe3e95738ed6fbe6e48e6
msg397467 - (view) Author: miss-islington (miss-islington) Date: 2021-07-14 05:40
New changeset 7e1d6308a3fc536719adcf1df0aa4e9953c12f8b by Miss Islington (bot) in branch '3.10':
bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107)
https://github.com/python/cpython/commit/7e1d6308a3fc536719adcf1df0aa4e9953c12f8b
msg397469 - (view) Author: miss-islington (miss-islington) Date: 2021-07-14 05:44
New changeset 94adfe6e2cdc9ba715b6d7068d8bd521ba6bf30b by Miss Islington (bot) in branch '3.9':
bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107)
https://github.com/python/cpython/commit/94adfe6e2cdc9ba715b6d7068d8bd521ba6bf30b
History
Date User Action Args
2021-07-14 05:47:33serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-14 05:44:16miss-islingtonsetmessages: + msg397469
2021-07-14 05:40:24miss-islingtonsetmessages: + msg397467
2021-07-14 05:19:41miss-islingtonsetpull_requests: + pull_request25677
2021-07-14 05:19:36miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25676
2021-07-14 05:19:36serhiy.storchakasetmessages: + msg397465
2021-07-13 06:06:31serhiy.storchakasetmessages: + msg397383
components: + Extension Modules, - Tkinter, C API
versions: + Python 3.10, Python 3.11
2021-07-13 06:03:15serhiy.storchakasetkeywords: + patch
nosy: + serhiy.storchaka

pull_requests: + pull_request25652
stage: patch review
2021-07-13 02:15:58ned.deilysetcomponents: + Tkinter
2021-07-12 07:00:30Stardust1225create