struct New_Info { int point; unsigned int size; string file; int line; New_Info(int p,unsigned int s,const char *f,int l) { point=p; size=s; file=f; line=l; } }; vector<New_Info> g_vNewInfo; void operator delete(void * p) { for(int i=0;i<g_vNewInfo.size();++i) { if(g_vNewInfo[i].point==(int)p) { g_vNewInfo.erase(g_vNewInfo.begin()+i); break; } } free(p); } void operator delete [](void * p) { delete(p); } void * operator new(unsigned int size,const char *file,int line) { void *p=operator new(size); New_Info ni((int)p,size,file,line); g_vNewInfo.push_back(ni); return p; } void PtError() { for(int i=0;i<g_vNewInfo.size();++i) { cout<<"内存泄露 文件:"<<g_vNewInfo[i].file.c_str()/ <<" 行数:"<<g_vNewInfo[i].line/ <<" 大小:"<<g_vNewInfo[i].size<<endl; } } #define new new(__FILE__,__LINE__) int _tmain(int argc, _TCHAR* argv[]) { int *a=new int(5); int *b=new int[10]; delete b; PtError(); return 0; }