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.

classification
Title: Listbox itemconfigure leaks memory
Type: Stage:
Components: Tkinter Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: abonet, jepler, nnorwitz, rhettinger
Priority: normal Keywords:

Created on 2003-08-02 08:01 by abonet, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
itemcfg.py abonet, 2003-08-02 08:03 Demonstration script
Messages (6)
msg17575 - (view) Author: Angelo Bonet (abonet) Date: 2003-08-02 08:01
Calling itemconfigure on Tkinter.Listbox to change item
colors seems to leak memory without bounds.  I've seen
this in Python 2.2 and 2.3 on SunOS, Tru64, and Linux.

Here's a small script that demostrates it:



import Tkinter as Tk
Lb = None

def update_lb ():
    global Lb    
    Lb.delete(0, Tk.END)

    for ii in range(100):
        Lb.insert(Tk.END, 'Item %d' % ii)
        Lb.itemconfigure(ii, bg='red')

    Lb.after(10, update_lb)


root = Tk.Tk()
Lb = Tk.Listbox(root)
Lb.pack()
Lb.after(1000, update_lb)
root.mainloop()
msg17576 - (view) Author: Angelo Bonet (abonet) Date: 2003-08-02 08:06
Logged In: YES 
user_id=716439

Sorry, but indentation got lost on script sample.  Look at
attached file instead.
msg17577 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-08-02 09:01
Logged In: YES 
user_id=80475

Try a gc.collect() to see if the problem persists.
msg17578 - (view) Author: Angelo Bonet (abonet) Date: 2003-08-02 20:40
Logged In: YES 
user_id=716439

Calling gc.collect() seems to reduce the rate at which
memory is leaking, but it does not eliminate the leak.
msg17579 - (view) Author: Jeff Epler (jepler) Date: 2003-08-03 15:24
Logged In: YES 
user_id=2772

The problem can be seen in an equivalent tcl script.  This may indicate that the problem is not in Python itself, but in the third-party Tcl/Tk library.

The script follows.  I hope indentation isn't lost, but at least Tk has curly braces for just such an emergency.

proc update_lb {} {
        .lb delete 0 end
        for {set i 0} {$i < 100} {incr i} {
                .lb insert end "Item $i"
                .lb itemco $i -bg red
        }
        after 10 update_lb
}

listbox .lb
pack .lb
after 10 update_lb
msg17580 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-06-16 03:10
Logged In: YES 
user_id=33168

Closing this since it seems to be related to Tcl/Tk, not Python.
History
Date User Action Args
2022-04-10 16:10:27adminsetgithub: 38998
2003-08-02 08:01:30abonetcreate