Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory use increase in function _tkinter._flatten #88774

Closed
Stardust1225 mannequin opened this issue Jul 12, 2021 · 5 comments
Closed

Memory use increase in function _tkinter._flatten #88774

Stardust1225 mannequin opened this issue Jul 12, 2021 · 5 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes extension-modules C modules in the Modules dir performance Performance or resource usage

Comments

@Stardust1225
Copy link
Mannequin

Stardust1225 mannequin commented Jul 12, 2021

BPO 44608
Nosy @serhiy-storchaka, @miss-islington, @Stardust1225
PRs
  • bpo-44608: Fix memory leak in _tkinter._flatten() #27107
  • [3.10] bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107) #27133
  • [3.9] bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107) #27134
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-07-14.05:47:33.362>
    created_at = <Date 2021-07-12.07:00:30.846>
    labels = ['extension-modules', '3.11', '3.9', '3.10', 'performance']
    title = 'Memory use increase in function _tkinter._flatten'
    updated_at = <Date 2021-07-14.05:47:33.361>
    user = 'https://github.com/Stardust1225'

    bugs.python.org fields:

    activity = <Date 2021-07-14.05:47:33.361>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-14.05:47:33.362>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2021-07-12.07:00:30.846>
    creator = 'Stardust1225'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44608
    keywords = ['patch']
    message_count = 5.0
    messages = ['397287', '397383', '397465', '397467', '397469']
    nosy_count = 3.0
    nosy_names = ['serhiy.storchaka', 'miss-islington', 'Stardust1225']
    pr_nums = ['27107', '27133', '27134']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue44608'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @Stardust1225
    Copy link
    Mannequin Author

    Stardust1225 mannequin commented Jul 12, 2021

    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

    @Stardust1225 Stardust1225 mannequin added topic-C-API 3.9 only security fixes performance Performance or resource usage labels Jul 12, 2021
    @serhiy-storchaka
    Copy link
    Member

    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.

    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir 3.10 only security fixes 3.11 only security fixes and removed topic-tkinter topic-C-API labels Jul 13, 2021
    @serhiy-storchaka
    Copy link
    Member

    New changeset f572cbf by Serhiy Storchaka in branch 'main':
    bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107)
    f572cbf

    @miss-islington
    Copy link
    Contributor

    New changeset 7e1d630 by Miss Islington (bot) in branch '3.10':
    bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107)
    7e1d630

    @miss-islington
    Copy link
    Contributor

    New changeset 94adfe6 by Miss Islington (bot) in branch '3.9':
    bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107)
    94adfe6

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes extension-modules C modules in the Modules dir performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants