Knowledge Base |

# BUG: Caching GDI Objects Causes Temporary GDI Resource Leak

Article ID: 118471

Article Last Modified on 2/14/2005

APPLIES TO

- Microsoft Windows Software Development Kit 3.1

This article was previously published under Q118471
3.10 WINDOWS kbprg kbbuglist

## SYMPTOMS

The amount of free GDI resources decreases as an application prints, especially over the course of several print jobs.
NOTE: The information in this article also applies to the screen; however, this issue more often impacts applications when printing, and therefore that is the specific subject of this article.

## CAUSE

The application caches GDI objects by creating them and not deleting them until the application terminates. Those objects are selected in and out of a printer Device Context (DC) when needed, over the course of several print jobs.
GDI creates a new physical object structure for each logical object that is selected into a printer DC. New physical objects are created even if the same logical objects are selected into a different printer DC. Those physical objects are not deleted until the corresponding logical objects are deleted. The more objects used in printing, and the more jobs that are printed using those objects, the more physical objects are created and more GDI resources are used up.

## RESOLUTION

Do not cache GDI objects (such as pens, brushes, and fonts). Instead, create them, use them during printing, and then delete them after each print job.

## STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

## MORE INFORMATION

This problem can be reproduced as follows:

1. Create a logical object such as a pen, brush, or font.
2. Repeat the following steps:
   1. Create a printer DC.
   2. Select the object into and out of the printer DC.
   3. Delete the printer DC.

With each iteration, GDI memory decreases.

Additional query words: buglist3.10 3.10 system resources

Keywords: kbbug kbpending KB118471