The information in this article applies to:
SUMMARY
Memory leaks are a problem in many applications. A concrete way of
determining memory leaks is to use the PHD Visual C++ class that is
provided in this article. By logging memory statistics in an application
using the PHD class, you can get a more precise idea of where a memory leak
is occurring.
MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center. Click the file names below to download the files: Phd.exeRelease Date: Oct-23-1998 For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. The following key files are included in the sample:
To use the PHD class, include the RKLeak.cpp file in your project. By including the header file, you will cause linkage to the PDH.lib library, which comes with the Visual C++ 6.0. You also need to add the PHD.dll file to your path so that the application will find it. The TestMain.cpp file contains the following sample code that demonstrates how to use the PHD class: Sample Code
The first use of the PHD constructor allows you to specify which items you want to monitor. These are the same items that are available in the Perfmon.exe application. The second use of the PHD constructor (no arguments) uses the following default column logs: private bytes, page file bytes, pool paged bytes, pool nonpaged bytes, and working set. As you can see from the sample code, the PHD class is used to put the suspected leaking API in a loop and periodically calls the PHD::logData method. Data is logged to file with name "<your EXE name>_perf.log" in the current directory. If the resulting log file shows a linear increase in private bytes, this increase does not imply a memory leak in the API, but merely a memory leak in the application. If the API is used incorrectly (for example, by not correctly freeing resources allocated by the initial call), the results show only a memory leak, not a faulty API. To narrow down the problem, create the simplest possible application that exercises the API in question. Visual C++ 5.x users need to comment out the following lines from RKLeak.h:
Other ToolsYou can search on the Web in FAQ pages for information on various third- party debuggers that can help you find memory leaks. For example, the following FAQ mentions several products:http://phantom.iweb.net/docs/C/faq/q18.2.htmlThe third-party products discussed here are manufactured by vendors independent of Microsoft; we make no warranty, implied or otherwise, regarding these products' performance or reliability. You should also note that sometimes these products can make false reports of leaks, but they still are very useful tools. Also, the Visual C++ heap debugging API is a useful tool for locating leaks. These include functions, such as _CrtMemDifference() and _CrtMemDumpAllObjectsSince(), which are documented in the Visual C++ Programmer's Guide in the Debug Function Reference section. These functions only detect leaks in your code and not leaks in other components. (c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Rick Anderson, Microsoft Corporation. Additional query words: leak hangs frozen
Keywords : kbfile kbsample kbVS97 kbVS600 |
Last Reviewed: December 15, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |