Microsoft KB Archive/184807

{|
 * width="100%"|

PRB: User32.dll Leaks Memory

 * }

Q184807

-

The information in this article applies to:


 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0
 * Microsoft Windows 95

-

SYMPTOMS
An increasing amount of memory appears to be consumed by an application that repeatedly loads and unloads the User32.dll. This may be caused by the application or a DLL used by the application that loads and unloads the User32.dll multiple times. If the User32.dll is loading and unloading several times, a message box might appear stating an error occurred.

CAUSE
User32.dll does not free its resources when it is unloaded.

RESOLUTION
Load User32.dll once per application.

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION
An application may notice that it is consuming an increasing amount of memory during its execution lifetime even though it does not use any functions that are exported from User32.dll. This may be caused by the application loading and unloading a DLL that uses a function exported from User32.dll.

Steps to Reproduce Behavior
  Create a DLL that calls a function exported from User32.dll. For example:      #include       #include 

BOOL WINAPI DllMain(HINSTANCE hInstance,                         DWORD dwReason, LPVOID lpReserved ) {        if (dwReason == DLL_PROCESS_ATTACH) HBRUSH hbr = GetSysColorBrush( COLOR_BTNFACE ); else if (dwReason == DLL_PROCESS_DETACH) {}        else if (dwReason == DLL_THREAD_ATTACH) {}        else if (dwReason ==DLL_THREAD_DETACH) {}        return TRUE; }   Create a console application that loads and unloads this DLL many times. For example:      #include "stdio.h"      void main (int argc, char **argv) {        int attempt = 0; HMODULE hInst;

while (attempt++ &lt; 2500) {           hInst = LoadLibrary ("..\\TestDLL.dll"); printf("Attempt %d: DLL Instance %08lX\n",attempt,hInst);

if (hInst == NULL) printf("LoadLibrary failed on attempt %d.\nLast error                      reports : %d\n", attempt,GetLastError); else FreeLibrary(hInst); } } 