17

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 the sake of this question, assume that the server has plenty of RAM (3+ GiB).

If an application (3rd party application in this case) leaks handles at a few hundred an hour, how many total handles can that application leak before other applications will run into troubles? By "troubles" I mean, for example, fail to start a thread, fail to open a file, and so on.

I've seen some servers (lightly loaded) run just fine with a process (usually a database process) using a few tens of thousands of handles, so the old 10000 handle limit is clearly not the issue here. (And that was a per-process limit anyway, so wouldn't affect my application which is well under that point.)

Can someone either answer the question or point me at some resources that explain about how many total handles a Windows server will allow before you effectively run out (of handles or other system resources)?

4
  • 1
    This seems more like a ServerFault type of question maybe. Jun 4, 2009 at 15:52
  • 1
    @Matthew Vines: I thought about that, but decided since I ran into this problem with a program I maintain, even though a 3rd party app is the one leaking the handles, that it belonged on the programmer web site. Were I an admin trying to figure this out, SF would be more appropriate.
    – Eddie
    Jun 4, 2009 at 16:02
  • This blog post from 2011 has some good empirical advice about which processes not to worry about. E.g. lsass.exe up to 30,000 (32-bit) or 50,000 (64-bit) is OK. Jun 5, 2018 at 5:45
  • My Task Manager currently shows 16,835,261 handles (Win10, uptime 7 days), so the limit of 16*1024*1024 or 16,777,216 doesn't seem to be correct. Jan 11, 2021 at 23:57

5 Answers 5

23

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.

2
  • 4
    In this article, it claims that you can reach up to 16 million handles per process. I've noticed also in windows xp that two of my processes exceeded the 10k limit. I'm confused.
    – jsirr13
    Oct 16, 2015 at 18:49
  • I guess the limit changed in the meanwhile, also see the answer of Thomas Weller.
    – Liviu
    Feb 23, 2018 at 11:34
6

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)

1
  • 1
    The debug tool is no longer relevant for Windows 7 and I assume later.
    – AnthonyVO
    Oct 2, 2014 at 16:18
6

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
6

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.

1
  • Note 1024 is 32 bit windows, and it was actually 32*1024*512. On 64 bit, it's actually 128 pointers * 512 pointers of 8 bytes per page * 256 entries of 16 bytes per page. Mar 19, 2021 at 5:18
2

According to this, 10000.

1
  • 1
    Those are only window object handles, and doesn't impact other types of handles (file, event, mutex, etc.)
    – josh poley
    Apr 21, 2014 at 19:30

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.