The information in this article applies to:
SUMMARY
The term "system resources" refers to two scarce system-wide
resources: the USER heap and the GDI heap. These two segments are each
limited to 64K, and they are both shared by all the applications
running under Windows.
MORE INFORMATIONFree System ResourcesThe Program Manager's About Program Manager dialog box displays a Free System Resources value. This value indicates the amount of room left in the heap (USER or GDI) with the smallest amount of free space. There is no Windows API call that an application can use to obtain this value.The easiest way to tell if an application is losing system resources is to examine Program Manager's Free System Resources value before and after running the application. It is acceptable if this value goes down a little the first time the application is run, however if the value decreases every time the application runs and exits, system resources are being allocated and not released. The GDI HeapThere are six GDI objects that a Windows program can create: pens, brushes, fonts, bitmaps, regions, and palettes. Space for each of these objects is allocated in the GDI heap.Normally, the life cycle of a GDI object requires that the following steps be performed:
The three general rules for deleting GDI objects are:
Creating GDI objects that are never destroyed is probably the most
common cause of lost system resources. A careful examination of every
place in the application's code that uses GDI objects will often
reveal the problem.
The debugging version of Windows 3.1 will FatalExit when an application terminates if a GDI object owned by the application has not been deleted. The USER HeapWhen an application creates window classes, windows, and menus, these objects take up room in the USER heap. When an application terminates, Windows usually reclaims the memory used by objects in the USER heap.Menus are a notable exception to this rule. Windows destroys the current menu of a window that is being destroyed. Windows does not destroy menus if they are not the current menu for any window. This can cause problems for applications that switch between multiple menus: the "extra" menus are not automatically destroyed when the application terminates. Therefore, if an application uses multiple menus, perform the following steps:
This means that an application cannot create an excessively large number of windows. Also, when calling the RegisterClass functions, make sure that the cbWndExtra and cbClassExtra fields of the WNDCLASS structure are explicitly set to 0 (zero) if no extra bytes are needed. Also, the following calls should always be matched:
Troubleshooting and Heap WalkerAs mentioned above, Program Manager's Free Systems Resources value can provide evidence that memory objects are not being reclaimed in the USER or GDI heaps.It is sometimes unclear whether or not a particular Windows API call that creates an object must be balanced by a later call to explicitly delete the object. The following is a simple test that can be performed to find out:
Additional query words: 3.00 3.10
Keywords : kb16bitonly kbResource kbSDKPlatform |
Last Reviewed: June 8, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |