This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author svenil
Recipients
Date 2005-10-30.21:49:23
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Tkinter.Menu.delete does not delete the commands
defined for the entries it deletes. Those objects
will be retained until the menu itself is deleted.

For example, after code like this:

    button = Menubutton(root, text='Window')
    menu = Menu(button)
    button['menu'] = menu
    def command():
	print 'command button pressed'
    menu.add_command(command=command)
    menu.delete(END)
    del command


the command function will still be referenced and
kept in memory - until the menu object itself is
destroyed.

This may not always be a serious problem, but in
my case the menu was a 'Window' menu and the
command was a method on a window top level widget,
so retaining a pointer to it after deleting the
menu entry kept a reference to that entire window,
with any associated data.

I have figured out a possible fix that is in the
attached file test_menuleak.py that contains some
test functions.

I also changed the comment - for as far as I can
see, the second optional index is actually
INCLUDED in the range of entries deleted.

Version info

Python 2.3.3 (#2, Mar 11 2004, 19:45:43) 
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2

I think it applies to all versions: I tested with
the latest 2.4.2 as well.


Sverker Nilsson
History
Date User Action Args
2007-08-23 14:35:53adminlinkissue1342811 messages
2007-08-23 14:35:53admincreate