-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
tkinter: avoid reference loops with Variables and Fonts #66266
Comments
$ ./python -m test.regrtest -ugui -v test_idle test_gc
... ====================================================================== 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. Diff is 1123 characters long. Set self.maxDiff to None to see it. ---------------------------------------------------------------------- |
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 ;-) |
regrtest_tracemalloc.patch: my patch for regrtest.py to dump the traceback where garbage objects where allocated using tracemalloc. (Note: you need to recompile Python to use tracemalloc on Python < 3.4.) |
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. |
ConfigDialog is a good guess as I added a minimal test this month. |
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. |
I agree that the patch shoukd also br applied to 3.4. |
F:\Python\dev>2\py27\pcbuild\python_d.exe -m test.regrtest -R :: -uall test_idle There are none with 3.4, so the new gc is doing its job. 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. |
New changeset 6b7f189daa62 by Terry Jan Reedy in branch '2.7': New changeset 1927f47a1838 by Terry Jan Reedy in branch '3.4': |
-R no longer finds leaks with current Idle tests. There might still be some in modules not tested. |
If there are no objections I'll commit the patch. |
New changeset 0b79c702abda by Serhiy Storchaka in branch '2.7': New changeset 873002eb8087 by Serhiy Storchaka in branch '3.4': New changeset f44f5daff665 by Serhiy Storchaka in branch 'default': |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: