Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am fresh to Visual C++. While moving forward in the book "Programming Windows with MFC", I came across GDI (Graphics Device Interface) and use of paint brush. The book says a brush cannot be created if your GDI is low on memory.

I want to know when and how does GDI get low on memory? And more important, what is the reason that we cannot create brush when GDI is low on memory?

share|improve this question

This depends a bit on the Version of Windows that you are targeting, but suffice to say that when you create a GDI object such as a brush or path, GDI will allocate some memory for that object either in your application memory or a shared server process memory (%SYSTEM\csrss.exe). In some versions of Windows, some of this memory is allocated in Kernel mode.

See this old, old, old article for how much memory and where

If you never release the object, GDI won't reclaim the memory. Suffice to say, there's a limit to how much is available (not necessarily proportional to the RAM in your PC). The actual limits vary, from Windows 95 upwards. It can be affected by overall application load (i.e. lots of graphical apps loaded, some of which are leaky), graphics driver issues, a number of concurrent users all competing for resource (e.g. Terminal server).

If you want to see it run out, do something like this:

CBitmap * pbm; while (true) { pbm = CBitmap::CreateBitmap(...); Sleep(0); }

Further reading:

Resource Leaks: Detecting, Locating, and Repairing Your Leaky GDI Code

BUG: GDI memory leak in Developer Studio IDE

GDI is low on memory - close one or more windows and try again

Out of memory messages when you have large numbers of programs running

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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