Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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:

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top