Microsoft KB Archive/184807: Difference between revisions
m (Text replacement - "../win32sdk/q" to "../") |
m (Text replacement - """ to """) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 58: | Line 58: | ||
<ol> | <ol> | ||
<li><p>Create a DLL that calls a function exported from User32.dll. For example:</p> | <li><p>Create a DLL that calls a function exported from User32.dll. For example:</p> | ||
<pre class="CODESAMP"> #include | <pre class="CODESAMP"> #include <windows.h> | ||
#include | #include <stdio.h> | ||
BOOL WINAPI DllMain(HINSTANCE hInstance, | BOOL WINAPI DllMain(HINSTANCE hInstance, | ||
Line 75: | Line 75: | ||
} </pre></li> | } </pre></li> | ||
<li><p>Create a console application that loads and unloads this DLL many times. For example:</p> | <li><p>Create a console application that loads and unloads this DLL many times. For example:</p> | ||
<pre class="CODESAMP"> #include | <pre class="CODESAMP"> #include "stdio.h" | ||
void main (int argc, char **argv) | void main (int argc, char **argv) | ||
{ | { | ||
Line 81: | Line 81: | ||
HMODULE hInst; | HMODULE hInst; | ||
while (attempt++ & | while (attempt++ < 2500) | ||
{ | { | ||
hInst = LoadLibrary ( | hInst = LoadLibrary ("..\\TestDLL.dll"); | ||
printf( | printf("Attempt %d: DLL Instance %08lX\n",attempt,hInst); | ||
if (hInst == NULL) | if (hInst == NULL) | ||
printf( | printf("LoadLibrary failed on attempt %d.\nLast error | ||
reports : %d\n | reports : %d\n", attempt,GetLastError()); | ||
else | else | ||
FreeLibrary(hInst); | FreeLibrary(hInst); | ||
Line 101: | Line 101: | ||
For additional information, please see the following article in the Microsoft Knowledge Base: | For additional information, please see the following article in the Microsoft Knowledge Base: | ||
<blockquote>[[../171145 | <blockquote>[[../171145|Q171145]] PRB: Resource Leaks in System Components</blockquote> | ||
Additional query words: GDI MFC | Additional query words: GDI MFC | ||
Latest revision as of 12:37, 21 July 2020
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 <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; }
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++ < 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 |