Microsoft KB Archive/184807

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:16, 19 July 2020 by X010 (talk | contribs) (Text replacement - "../win32sdk/q" to "../")

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

  1. Create a DLL that calls a function exported from User32.dll. For example:

          #include <windows.h>
          #include <stdio.h>
    
          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;
          } 
  2. 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);
             } 

    }



REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

Q171145 PRB: Resource Leaks in System Components

Additional query words: GDI MFC

Keywords : kbAPI kbDLL kbKernBase kbPerfMon _IK kbGrpDSKernBase
Issue type : kbprb
Technology : kbWinNTsearch kbWinNTWsearch kbWinNTW400 kbWinNTW400search kbWinNT400xsearch kbWinNTSsearch kbWinNTS400xsearch kbWinNTS400 kbWin95search kbZNotKeyword3


Last Reviewed: December 16, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.