22

Have an application with a GDI leak that will eventually hit 10,000 allocated GDI objects and crash. I tried increasing the GDIProcessHandleQuota to 20,000, but the program still crashed when it reached 10,000 objects. We're currently working on patching this leak, but out of curiosity--is there a way to increase the GDI limit for a single process? Or is 10k an individual application's hard limit?

Wolf
  • 9,679
  • 7
  • 62
  • 108
Micky
  • 345
  • 1
  • 4
  • 13
  • 1
    Increasing `GDIProcessHandleQuota` to `20,000` worked for me. Had to restart the System after the registry changes. Updated the Registry key at `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\GDIProcessHandleQuota` – Abhinav Galodha Mar 07 '18 at 17:41

3 Answers3

16

10K is a hard limit.

GDI objects represent graphical device interface resources like fonts, bitmaps, brushes, pens, and device contexts (drawing surfaces). As it does for USER objects, the window manager limits processes to at most 10,000 GDI objects [...]

Mark Russinovich has a series of articles that go in-depth about the various limits in Windows. You might find these two useful:

Another good article from Raymond Chen:

Christopher Edwards
  • 6,589
  • 8
  • 43
  • 57
Derek Park
  • 45,824
  • 15
  • 58
  • 76
  • 1
    Thanks for the info. I had browsed the Pushing the Limits of Windows articles before posting here and noticed that Mark R. doesn't show you how to modify the registry to expand the default GDI limit beyond 10k, so I figured it may have been something he overlooked. I'm still confused why this number can be as high as 65535 if it doesn't have a noticeable effect on my machine. I can consume well-beyond a total of 10k objects for all my processes with no lag in Windows, it's not until one application reaches 10k when I get a crash. – Micky Mar 15 '12 at 16:38
  • 5
    `10K is a hard limit.` this seems not to be true. Can you please add details about the relation of the limitation you refer to to the howto in [JimR's answer](http://stackoverflow.com/a/9723784/2932052) – Wolf Jan 14 '15 at 13:09
  • 2
    There is a Registry key called GDIProcessHandleQuota. Doesn't seem to be so hard to change that limit. I think you mixed GDI handles and User handles. – Thomas Weller Nov 17 '17 at 12:48
  • 1
    I know this thread is old, but for those who want to see the Russinovich links above (which are dead, at lest to me), here are the live ones: https://techcommunity.microsoft.com/t5/windows-blog-archive/pushing-the-limits-of-windows-user-and-gdi-objects-8211-part-1/ba-p/723881 and https://techcommunity.microsoft.com/t5/windows-blog-archive/pushing-the-limits-of-windows-user-and-gdi-objects-8211-part-2/ba-p/723897 – jimo3 Jul 25 '20 at 15:54
13

There is a solution that might work. I deal with a misbehaved vendor's app here that allocates tons of GDI objects and this solution allows it to work most of the time...

Do

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems" /v windows

Look for SharedSection= which should be 3 numbers separated by commas. Increase the middle number by 1024 at a time and see if that solves your problem. You are controlling the amount of "desktop heap" with this variable which has in the past allowed me to get a misbehaving GDI running.

Look at KB184802 for a little more info. Search for SharedSection to find the relevant part of the page.

JimR
  • 15,513
  • 2
  • 20
  • 26
  • Bingo! I bumped up the desktop heap and am now able to go well beyond 10,000 GDI objects. Our lead developer already came up with a patch, but now my curiosity is resolved. Thanks – Micky Mar 15 '12 at 17:57
  • Hi! my SharedSection is set to 1024,20480,768 but my python.exe still crashes. I've read that it is not safe to increase desktop heap over 20480? what are your opinion? – Aleksandar Jul 15 '13 at 10:44
  • @Aleksandar: If I remember correctly, the total from all of those numbers cannot exceed 48MB. Those numbers set aside memory in kilobytes. There are some other limits as well based on how many and what services you have running. Read the first 3 links in Derek Parks answer for good background. Also make sure you're not creating more than 10,000 GDI objects. – JimR Jul 16 '13 at 06:46
1

I am able to increase my GDI objects from 10000 to 15000 by changing ONLY the GDIProcessHandleQuota, but this requires a reboot to take effect. I did not have to change my SharedSection values, only the reboot was required.

While 10000 seems like a big number, my application has a large UI with lots of buttons, brushes, images, icons, etc. Once the application starts up, the number of objects only increases if the user does something that merits an increase. No GDI objects are leaking from the application. To test my solution I did add a "leak" method, so I could watch in the task manager what happened as the number of GDI objects increased beyond various limits.

Chilledrat
  • 2,593
  • 3
  • 28
  • 38
wolf
  • 11
  • 1