[ python-Patches-1731706 ] tkinter memory leak problem

"SourceForge.net" <[email protected]>
Newsgroups gmane.comp.python.patches
Message-ID <[email protected]>
Patches item #1731706, was opened at 2007-06-05 14:47
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1731706&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
>Category: Tkinter
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Robert Hancock (robhancock)
Assigned to: Martin v. Löwis (loewis)
Summary: tkinter memory leak problem

Initial Comment:
We have a Python application which displays a GUI using Tkinter and Pmw. We have seen that over time the memory usage of the app seems to continuously increase and eventually use up all of the system's RAM. I ran the app under Valgrind, and this leak seems to account for most of the memory that it detects as being leaked:

==31141== 2,630,208 (806,400 direct, 1,823,808 indirect) bytes in 21 blocks are definitely lost in loss record 156 of 159
==31141==    at 0x4A05809: malloc (vg_replace_malloc.c:149)
==31141==    by 0x368268844A: TclThreadAllocObj (in /usr/lib64/libtcl8.4.so)
==31141==    by 0x3682686BA0: Tcl_NewStringObj (in /usr/lib64/libtcl8.4.so)
==31141==    by 0x8B3B258: AsObj (_tkinter.c:902)
==31141==    by 0x8B3BB1C: Tkapp_CallArgs (_tkinter.c:1149)
==31141==    by 0x8B3BD67: Tkapp_CallProc (_tkinter.c:1224)
==31141==    by 0x36826786D4: Tcl_ServiceEvent (in /usr/lib64/libtcl8.4.so)
==31141==    by 0x3682678A20: Tcl_DoOneEvent (in /usr/lib64/libtcl8.4.so)
==31141==    by 0x8B3F55B: Tkapp_MainLoop (_tkinter.c:2532)
==31141==    by 0x36900949D9: PyEval_EvalFrame (in /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x3690095904: PyEval_EvalCodeEx (in /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x369009405E: PyEval_EvalFrame (in /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x3690094485: PyEval_EvalFrame (in /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x3690095904: PyEval_EvalCodeEx (in /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x3690095951: PyEval_EvalCode (in /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x36900B1EA8: (within /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x36900B3357: PyRun_SimpleFileExFlags (in /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x36900B979C: Py_Main (in /usr/lib64/libpython2.4.so.1.0)
==31141==    by 0x368161D8A3: (below main) (in /lib64/libc-2.5.so)

Looking at the code in _tkinter.c, I am not sure how the Tkapp_CallDeallocArgs function is supposed to get called in the case where we push the request onto the Tcl interpreter thread in Tkapp_Call. That call is what would presumably release this allocated memory.

This is using Python 2.4.3 and tcl/tk 8.4.13. Looking at Python SVN, there does not seem to be any relevant code changes in _tkinter.c in later versions..

----------------------------------------------------------------------

>Comment By: Neal Norwitz (nnorwitz)
Date: 2007-06-06 22:24

Message:
Logged In: YES 
user_id=33168
Originator: NO

Thanks for the report and patch!

Can you attach a python program that demonstrates these bugs? I'd like to
add tests for these.  The memory leak looks pretty straightforward, but I
don't know about the other Condition changes.

----------------------------------------------------------------------

Comment By: Robert Hancock (robhancock)
Date: 2007-06-06 09:53

Message:
Logged In: YES 
user_id=1809277
Originator: YES

Found a couple of issues in _tkinter.c that appear to have been causing
this:

-When calls were forwarded onto the Tcl interpreter thread, the
Tkapp_CallDeallocArgs function was never called to clean up the converted
arguments after the call.

-Tcl_Condition variables were never finalized after being used. According
to the Tcl documentation, if this is not done they are only cleaned up on
program exit, resulting in them accumulating during runtime.

I'm attaching a patch against Python 2.4.3 to fix this problem. It likely
applies to later versions as well.
File Added: python-2.4.3-memleak-fix.patch

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1731706&group_id=5470
_______________________________________________
Patches mailing list
[email protected]
http://mail.python.org/mailman/listinfo/patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.