Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue22068

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:tkinter: avoid reference loops with Variables and Fonts
Type:behaviorStage:resolved
Components:TkinterVersions:Python 3.4, Python 3.5, Python 2.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: kbk, python-dev, roger.serwy, serhiy.storchaka, terry.reedy, vstinner
Priority:normalKeywords:patch

Created on2014-07-25 15:34 byserhiy.storchaka, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
tracemalloc.txtvstinner,2014-07-25 15:50
regrtest_tracemalloc.patchvstinner,2014-07-25 15:52review
tkinter_refloops-2.7.patchserhiy.storchaka,2014-07-26 09:16review
Messages (12)
msg223958 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2014-07-25 15:34
$ ./python -m test.regrtest -ugui -v test_idle test_gc...======================================================================FAIL: test_saveall (test.test_gc.GCTests)----------------------------------------------------------------------Traceback (most recent call last):  File "/home/serhiy/py/cpython-2.7/Lib/test/test_gc.py", line 200, in test_saveall    self.assertEqual(gc.garbage, [])AssertionError: Lists differ: [<Tkinter.StringVar instance a... != []First list contains 24 additional elements.First extra element 0:PY_VAR0Diff is 1123 characters long. Set self.maxDiff to None to see it.----------------------------------------------------------------------
msg223960 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2014-07-25 15:50
It looks like test_idle leaks uncollectable objects.I modified regrtest to use tracemalloc, I attach the output: tracemalloc.txt. Good luck to find the leaks ;-)
msg223961 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2014-07-25 15:52
regrtest_tracemalloc.patch: my patch for regrtest.py to dump the traceback where garbage objects where allocated using tracemalloc.http://pytracemalloc.readthedocs.org/(Note: you need to recompile Python to use tracemalloc on Python < 3.4.)
msg223963 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2014-07-25 16:34
Indeed, there are a lot of small reference loops in ConfigDialog. Tk variables save reference to the dialog and the dialog saves references to variables. Either variables should be created with different argument (i.e. self.parent), or they should be deleted when ConfigDialog is destroyed.
msg224021 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2014-07-26 06:43
ConfigDialog is a good guess as I added a minimal test this month.I will try to revise to not create loops in the first place.
msg224033 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2014-07-26 09:16
Here is a patch against 2.7 which get rid of reference loops in Tk variables and Font. This will fix not only ConfigDialog, but any similar user code.In 3.4+ such reference loops are successfully resolved, but I think we should foreport this path to 3.4+ because it also fixes other minor bug: callbacks registered to trace variable now live while the variable lives, not while widget lives.
msg224042 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2014-07-26 11:41
I agree that the patch shoukd also br applied to 3.4.
msg224092 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2014-07-27 00:11
F:\Python\dev>2\py27\pcbuild\python_d.exe -m test.regrtest -R :: -uall test_idletest_idle leaked [1945, 1945, 1945, 1945] references, sum=7780There are none with 3.4, so the new gc is doing its job.There are also none with test_configdialog renamed xtest... ,GetCfgSectionNameDialog.__init__ in configSectionNameDialog.py saves self.parent for later use as the parent for XyxVars.  I am looking at doing the same for config dialog.
msg224361 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-07-30 23:25
New changeset6b7f189daa62 by Terry Jan Reedy in branch '2.7':Issue#22068: Don't create self reference cycles in idlelib.ConfigDialog.http://hg.python.org/cpython/rev/6b7f189daa62New changeset1927f47a1838 by Terry Jan Reedy in branch '3.4':Issue#22068: Don't create self reference cycles in idlelib.ConfigDialog.http://hg.python.org/cpython/rev/1927f47a1838
msg224363 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2014-07-30 23:32
-R no longer finds leaks with current Idle tests. There might still be some in modules not tested.
msg225273 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2014-08-13 10:11
If there are no objections I'll commit the patch.
msg225440 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-08-17 12:34
New changeset0b79c702abda by Serhiy Storchaka in branch '2.7':Issue#22068: Avoided reference loops with Variables and Fonts in Tkinter.http://hg.python.org/cpython/rev/0b79c702abdaNew changeset873002eb8087 by Serhiy Storchaka in branch '3.4':Issue#22068: Avoided reference loops with Variables and Fonts in Tkinter.http://hg.python.org/cpython/rev/873002eb8087New changesetf44f5daff665 by Serhiy Storchaka in branch 'default':Issue#22068: Avoided reference loops with Variables and Fonts in Tkinter.http://hg.python.org/cpython/rev/f44f5daff665
History
DateUserActionArgs
2022-04-11 14:58:06adminsetgithub: 66266
2014-08-17 13:47:14serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2014-08-17 12:34:53python-devsetmessages: +msg225440
2014-08-13 10:11:50serhiy.storchakasetmessages: +msg225273
2014-07-30 23:32:43terry.reedysetmessages: +msg224363
components: - IDLE, Tests
title: test_idle leaks uncollectable objects -> tkinter: avoid reference loops with Variables and Fonts
2014-07-30 23:25:11python-devsetnosy: +python-dev
messages: +msg224361
2014-07-29 22:29:27vstinnersettitle: test_gc fails after test_idle -> test_idle leaks uncollectable objects
2014-07-27 00:11:49terry.reedysetmessages: +msg224092
versions: + Python 3.4, Python 3.5
2014-07-26 11:41:03vstinnersetmessages: +msg224042
2014-07-26 09:16:37serhiy.storchakasetfiles: +tkinter_refloops-2.7.patch
messages: +msg224033

assignee:serhiy.storchaka
components: + Tkinter
stage: patch review
2014-07-26 06:43:31terry.reedysetmessages: +msg224021
2014-07-25 16:34:36serhiy.storchakasetmessages: +msg223963
2014-07-25 15:52:27vstinnersetfiles: +regrtest_tracemalloc.patch
keywords: +patch
messages: +msg223961
2014-07-25 15:50:42vstinnersetfiles: +tracemalloc.txt
nosy: +vstinner
messages: +msg223960

2014-07-25 15:34:59serhiy.storchakacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp