[Patches] [ python-Patches-749190 ] memory leak of "callit"s using after_cancel in tkinter

SourceForge.net noreply@sourceforge.net
Wed, 04 Jun 2003 15:08:41 -0700


Patches item #749190, was opened at 2003-06-04 15:06
Message generated for change (Settings changed) made by pjanzen
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=749190&group_id=5470

Category: Tkinter
Group: Python 2.2.x
>Status: Deleted
>Resolution: Duplicate
Priority: 5
Submitted By: Paul Janzen (pjanzen)
Assigned to: Nobody/Anonymous (nobody)
Summary: memory leak of "callit"s using after_cancel in tkinter 

Initial Comment:
I have observed a memory leak in tkinter when using 
after_cancel to disable pending alarm callbacks. 

The Tkinter.py code for "after" builds a function object 
with enough information to dispose of itself after the 
user's callback has been executed.  This function object 
("callit") is registered with _register(). 

In the normal flow, the Tk main loop wakes up after the 
allotted time has passed and invokes the callit function, 
which in turn calls the user-provided function and 
deletes the callit() function from the Tcl interpreter and 
the Python interpreter. 

However, when the program aborts the "after" callback 
with "after_cancel," this cleanup is not performed.  As a 
result, the "callit" callback remains registered in both Tcl 
and Python interpreters.  

(By way of background, I am developing a program that 
communicates with a device; every time I send data to 
the device, I set up an alarm handler which gets 
canceled when the device responds.  So I am performing 
after and after_cancel on every transaction.  The 
memory usage can grow very quickly in this situation.) 

The attached patch is my quick hack at solving the 
problem.  There may be a more elegant way to retrieve 
the Python callback name from the after id, but this 
method does stop the memory leaks.

The patch is against the Tkinter.py distributed with 
ActiveState 2.2.2 build 224; however, the problem 
appears to still be present in CVS HEAD. 

Thanks, 

-- Paul


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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=749190&group_id=5470