How many Windows handles in use is “too many”?

前端 未结 5 1087
再見小時候
再見小時候 2021-02-03 10:49

I understand that the answer to this question may depend on registry settings and on the version of Windows, and perhaps on the amount of RAM if there is not enough memory. For

相关标签:
5条回答
  • 2021-02-03 11:11

    According to this, 10000.

    0 讨论(0)
  • 2021-02-03 11:21

    The desktop heap, which is a pool of memory where the real "stuff" the handle represents lives. It's sometimes not so much how many handles you have allocated but how much memory each object under that handle is using. You can debug the heap this way. It is a pain to install.

    (this was recycled from another one of my answers)

    0 讨论(0)
  • 2021-02-03 11:25

    Since those values could change with new Windows versions, you can use the SysInternals tool TestLimit / TestLimit64 to get a rough estimate. The x64 version may run for a while, especially for the memory test (it might use the hard disk (swap file) to get more virtual memory).

    Get the tools from http://live.sysinternals.com/WindowsInternals/ or http://download.sysinternals.com/files/TestLimit.zip

    Command line options:

    -p check process limit
    -t check thread limit
    -h check handle limit
    -u check user handle limit
    
    0 讨论(0)
  • 2021-02-03 11:26

    As per this recent blog post the limit of total handles for a process in Windows 10 is hard-coded as 16*1024*1024 or 16,777,216.

    As the Windows Executive (see also here) also stores some tracking information about handles, the actual limits are 16,711,680 for 64-bit Windows 10 and 16,744,448 for 32-bit Windows 10:

    The Executive allocates handle tables on demand in page-sized blocks that it divides into handle table entries. That means a page, which is 4096 bytes on both x86 and x64, can store 512 entries on 32-bit Windows and 256 entries on 64-bit Windows. The Executive determines the maximum number of pages to allocate for handle entries by dividing the hard-coded maximum,16,777,216, by the number of handle entries in a page, which results on 32-bit Windows to 32,768 and on 64-bit Windows to 65,536. Because the Executive uses the first entry of each page for its own tracking information, the number of handles available to a process is actually 16,777,216 minus those numbers, which explains the results obtained by Testlimit: 16,777,216-65,536 is 16,711,680 and 16,777,216-65,536-32,768 is 16,744,448.

    0 讨论(0)
  • 2021-02-03 11:27

    See Raymond Chen's post on this topic. The window manager enforces a limit of 10K per process, and has a total limit of 32K across the system. So if it "only" leaks 100 handles per hour, then you have a few days of uptime before it starts misbehaving.

    Note that not all handles are equal. Window handles are not DB handles, for example, and may follow different rules. So this restriction might not apply, depending on what sort of handles the program is leaking. Also read this blog post.

    0 讨论(0)
提交回复
热议问题