| Ticket UUID: | 3109856 | |||
| Title: | canvas itemconfigure memory leak - Tk_Uid | |||
| Type: | Bug | Version: | 8.5.9, 8.6.18 | |
| Submitter: | hobbs | Created on: | 2010-11-15 23:59:01 | |
| Subsystem: | 05. Canvas Items | Assigned To: | hobbs | |
| Priority: | 6 | Severity: | ||
| Status: | Closed | Last Modified: | 2026-10-22 17:22:36 | |
| Resolution: | Fixed | Closed By: | serhiy.storchaka | |
| Closed on: | 2026-09-22 12:24:31 | |||
| Description: |
The attached script indicates a memory leak with canvas itemconfigure (possibly with just color handling). Memory leak seen on both Windows and Linux. This was first reported via Tkinter-discuss list. | |||
| User Comments: |
serhiy.storchaka added on 2026-09-22 12:24:31:
Jan's guess was right, and the measurements confirm it: in 8.6 Tk_GetColor() takes a Tk_Uid, so every new color name is interned permanently, about 64 bytes per name. With the pattern of the attached script (400 items, random colors) 8.6.18 grows linearly, from 15.0 MB to 19.0 MB over 60000 itemconfigure calls, while 9.0.5 and 9.1 stay flat. Repeating the same colors does not grow in any version, and other options (-width, -tags with a known tag) do not grow either. The new core API asked for in this ticket is in 9.0: [fc05409ebc] ([0189a9ae39]) changed Tk_GetColor() and friends to take a "const char *" instead of a Tk_Uid, so the color names are no longer interned. The same change carries out the patch proposed in [1870330]. In 8.6 this cannot be fixed without changing the same API, so the leak remains there. hobbs added on 2010-11-17 04:19:05: Reconfirmed for my aging memory that Tk_GetColor is Tk_Uid based (layered over XIds). We'd have to add new core APIs to get around this. See tkColor.c. hobbs added on 2010-11-17 00:06:55: Ah, I had ruled out the Tk_Uid of canvas items, not realizing that colors themselves where Tk_Uids as well. Each random color would have a new memory element, but only once per instance of that color. nijtmans added on 2010-11-16 12:43:09: Just a wild guess: color options in Canvas are handled as Tk_Uid, so this doesn't surprise me. hobbs added on 2010-11-16 06:59:01: File Added - 393398: itemconf.tcl | |||
Attachments:
- itemconf.tcl [download] added by hobbs on 2010-11-16 06:59:01. [details]
