SAMPLE: Using the PHD Class to Isolate Memory LeaksID: Q194655
|
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.
The self-extracting PHD.EXE is a sample that that demonstrates how to use
the included PHD class to prove/disprove a memory leak. The PHD class is a
thin wrapper around the Performance Helper Functions from the Windows NT
resource kit. This code works only on Windows NT.
The following file is available for download from the Microsoft Software Library:
~ PHD.exeRelease Date: Oct-23-1998
Q119591 How to Obtain Microsoft Support Files from Online Services
FileName Description
---------------------------------------------------------
PDH.dll Contains helper functions used by PHD.
RKLeak.cpp Contains the code for the PHD class.
RKLeak.h Header file for the PHD class.
TestMain.cpp A simple program to demonstrate the PHD class.
**************************************************
#include "rkLeak.h"
void main()
{
char *myCntrs[]={
"\\Memory\\Available bytes",
"\\Memory\\committed bytes",
"\\Memory\\pool Paged bytes",
"\\Memory\\pool Nonpaged bytes",
};
PHD mphd2(myCntrs,sizeof(myCntrs)/sizeof(myCntrs[0]));
PHD mphd;
const int arSize=4096;
for (int i=0;i<5;i++){
double *d = new double[arSize];
d[0]= 1.; d[arSize-1] = 2.; // Force to committed mem.
mphd.logData(i);
mphd2.logData(i);
}
***************************************************
#undef PdhOpenQuery // PdhOpenQueryA
extern "C" long __stdcall
PdhOpenQuery (
IN LPCSTR szDataSource,
IN DWORD dwUserData,
IN HQUERY *phQuery
);
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.
Additional query words: leak hangs frozen
Keywords : kbfile kbsample kbVS97 kbVS600
Version : WINDOWS:6.0,97
Platform : WINDOWS
Issue type :
Last Reviewed: April 13, 1999