Tk Source Code

View Ticket
Login
Ticket UUID: 870844
Title: WinTk: many menus in menubar won't popup
Type: Bug Version: 8.4.6, 8.6.18, 9.0.5, 9.1b1
Submitter: vincentdarley Created on: 2004-01-05 11:22:43
Subsystem: 13. Win Menus Assigned To: tmh
Priority: 5 Medium Severity:
Status: Open Last Modified: 2026-09-21 21:18:06
Resolution: None Closed By:
    Closed on:
Description:
The attached script recursively creates some submenus
in a menubar.  Unfortunately, only the first menu
actually pops up (in any of Tk 8.3/8.4/8.5), and
attempting to launch two wish processes with this
script simply fails (subsequent processes don't manage
to launch, it seems).

This is on WinXP

catch {console show}

proc mr {w count e} {
    for {set i 0} {$i < 5} {incr i} {
if {$e} {
    $w insert end command \
      -label "entry$count$i" -command "foo $i"
}
if {$count > 0} {
    set m $w.m$count$i
    menu $m
    $w insert end cascade \
      -label "sub$count$i" -menu $m
    mr $m [expr {$count -1}] 1
}
    }
}
proc foo {args} {
    puts stderr $args
}

menu .mb
. configure -menu .mb
mr .mb 5 0
update
User Comments: serhiy.storchaka added on 2026-09-21 21:18:06:

Reproduced on Windows 11 with 8.6 and 9.1: with the script (3905 menus) the menus of the menubar do not pop up; with 155 menus they do. Every menu uses one USER handle (its Win32 menu), the clones made for the menubar double that (7844 handles after the script), and Windows allocates about one more per menu of the whole menubar while one of its menus is open (measured: +91 for 85 menus, +856 for 850 menus, whichever menu is opened). So a menubar with N menus needs about 3N USER handles when a menu is opened, and with N > ~3300 the default quota of 10000 per process is exceeded and the popup cannot be created. This is the same limit as in [31085d2747] (10000 ttk widgets). Tk could avoid the doubling by not creating the Win32 menus of the originals, which are never displayed on Windows, but that is a larger change for the sake of menubars with thousands of menus; the quota can be raised in the registry (USERProcessHandleQuota, up to 18000).


vincentdarley added on 2004-04-02 22:49:47:
Logged In: YES 
user_id=32170

Appears to be the code grabbing large numbers of "USER
handle objects".  The odd thing is the it seems to construct
the menus ok, but then it is only when trying to post them
that everything fails.

Bug still in 8.5a2

vincentdarley added on 2004-01-07 01:29:13:
Logged In: YES 
user_id=32170

This seems to be some sort of windows resource leak or
similar issue.  After running this script, I can't open any
other windows (even other applications). Such actions simply
fail....

vincentdarley added on 2004-01-05 18:22:43:

File Added - 72300: menutest.tcl

Attachments: