473,624 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find Memory Leak

I have been working on VB, ASP for quite a long time. Very Recently (
From past 1 month) I am managing a VC++ project. I am trying to use
the code which i downloaded from the internet to find the memory leak
in the VC++ dll which is causing the servers to crash. I am getting
the compilation error on this particular line

void * __cdecl operator new(unsigned int size,const char *file, int
line)

error C2059: syntax error : 'string'
error C2091: function returns function
error C2809: 'operator new' has no formal parameters

which I don't know how to resolve. It would be a great help if any
body throw some light on this . Thank in advance

Below is the code which i cut and pasted from your article.

Header File
---------------
/ stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_ST DAFX_H__ADEF40E 8_7DC0_4B4B_9B5 5_DC8B3C32A60E_ _INCLUDED_)
#define AFX_STDAFX_H__A DEF40E8_7DC0_4B 4B_9B55_DC8B3C3 2A60E__INCLUDED _
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <list>
#include <iostream>
using namespace std ;
int size;
const char *file;
int line;
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common
Controls
#ifndef _AFX_NO_AFXCMN_ SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_ SUPPORT
#ifdef _DEBUG
#define DEBUG_NEW new(__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
#define new DEBUG_NEW

CPP File
-----------
// stdafx.cpp : source file that includes just the standard includes
// Sample.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#define __cdecl
#include "stdafx.h"
typedef struct {
DWORD address;
DWORD size;
char file[64];
DWORD line;
} ALLOC_INFO;
typedef list<ALLOC_INFO *> AllocList;
AllocList *allocList;
void AddTrack(DWORD addr, DWORD asize, const char *fname, DWORD lnum)
{
ALLOC_INFO *info;
if(!allocList) {
allocList = new(AllocList);
}
info = new(ALLOC_INFO) ;
info->address = addr;
strncpy(info->file, fname, 63);
info->line = lnum;
info->size = asize;
allocList->insert(allocLi st->begin(), info);
};
void RemoveTrack(DWO RD addr)
{
AllocList::iter ator i;
if(!allocList)
return;
for(i = allocList->begin(); i != allocList->end(); i++)
{
if((*i)->address == addr)
{
allocList->remove((*i)) ;
break;
}
}
};
void DumpUnfreed()
{
AllocList::iter ator i;
DWORD totalSize = 0;
char buf[1024];
if(!allocList)
return;
for(i = allocList->begin(); i != allocList->end(); i++) {
sprintf(buf, "%-50s:\t\tLINE %d,\t\tADDRESS %d\t%d unfreed\n",
(*i)->file, (*i)->line, (*i)->address, (*i)->size);
OutputDebugStri ng(buf);
totalSize += (*i)->size;
}
sprintf(buf, "-----------------------------------------------------------\n");
OutputDebugStri ng(buf);
sprintf(buf, "Total Unfreed: %d bytes\n", totalSize);
OutputDebugStri ng(buf);
};
#ifdef _DEBUG
void * __cdecl operator new(unsigned int size,const char *file, int
line)
{
void *ptr = (void *)malloc(size);
AddTrack((DWORD )ptr, size, file, line);
return(ptr);
};
inline void __cdecl operator delete(void *p)
{
RemoveTrack((DW ORD)p);
free(p);
};
#endif
Jul 19 '05 #1
1 13662
If you are using the MFC part of it then you can use
CMemoryState object to find memory leaks ....

Amol

sr*********@hot mail.com (Harsha) wrote in message news:<ca******* *************** ****@posting.go ogle.com>...
I have been working on VB, ASP for quite a long time. Very Recently (
From past 1 month) I am managing a VC++ project. I am trying to use
the code which i downloaded from the internet to find the memory leak
in the VC++ dll which is causing the servers to crash. I am getting
the compilation error on this particular line

void * __cdecl operator new(unsigned int size,const char *file, int
line)

error C2059: syntax error : 'string'
error C2091: function returns function
error C2809: 'operator new' has no formal parameters

which I don't know how to resolve. It would be a great help if any
body throw some light on this . Thank in advance

Below is the code which i cut and pasted from your article.

Header File
---------------
/ stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_ST DAFX_H__ADEF40E 8_7DC0_4B4B_9B5 5_DC8B3C32A60E_ _INCLUDED_)
#define AFX_STDAFX_H__A DEF40E8_7DC0_4B 4B_9B55_DC8B3C3 2A60E__INCLUDED _
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <list>
#include <iostream>
using namespace std ;
int size;
const char *file;
int line;
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common
Controls
#ifndef _AFX_NO_AFXCMN_ SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_ SUPPORT
#ifdef _DEBUG
#define DEBUG_NEW new(__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
#define new DEBUG_NEW

CPP File
-----------
// stdafx.cpp : source file that includes just the standard includes
// Sample.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#define __cdecl
#include "stdafx.h"
typedef struct {
DWORD address;
DWORD size;
char file[64];
DWORD line;
} ALLOC_INFO;
typedef list<ALLOC_INFO *> AllocList;
AllocList *allocList;
void AddTrack(DWORD addr, DWORD asize, const char *fname, DWORD lnum)
{
ALLOC_INFO *info;
if(!allocList) {
allocList = new(AllocList);
}
info = new(ALLOC_INFO) ;
info->address = addr;
strncpy(info->file, fname, 63);
info->line = lnum;
info->size = asize;
allocList->insert(allocLi st->begin(), info);
};
void RemoveTrack(DWO RD addr)
{
AllocList::iter ator i;
if(!allocList)
return;
for(i = allocList->begin(); i != allocList->end(); i++)
{
if((*i)->address == addr)
{
allocList->remove((*i)) ;
break;
}
}
};
void DumpUnfreed()
{
AllocList::iter ator i;
DWORD totalSize = 0;
char buf[1024];
if(!allocList)
return;
for(i = allocList->begin(); i != allocList->end(); i++) {
sprintf(buf, "%-50s:\t\tLINE %d,\t\tADDRESS %d\t%d unfreed\n",
(*i)->file, (*i)->line, (*i)->address, (*i)->size);
OutputDebugStri ng(buf);
totalSize += (*i)->size;
}
sprintf(buf, "-----------------------------------------------------------\n");
OutputDebugStri ng(buf);
sprintf(buf, "Total Unfreed: %d bytes\n", totalSize);
OutputDebugStri ng(buf);
};
#ifdef _DEBUG
void * __cdecl operator new(unsigned int size,const char *file, int
line)
{
void *ptr = (void *)malloc(size);
AddTrack((DWORD )ptr, size, file, line);
return(ptr);
};
inline void __cdecl operator delete(void *p)
{
RemoveTrack((DW ORD)p);
free(p);
};
#endif

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3634
by: Elbert Lev | last post by:
#When I'm running this script on my windows NT4.0 box, #every time dialog box is reopened there is memory growth 384K. #Bellow is the text I sent to Stephen Ferg (author of easygui) # I have tested the pure Tkinter, # by modifiing on of the examples in the distribution. # This little guy also exibits the same behaviour. # Namely: every time the window is closed and reoppend, # there is memory leak of several hundreds 384K
8
3406
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? In nut shell, what is/are the realtion/s between the Memory Leak and Memory Corruption. Juts Theoritical Assumtion below:
17
4794
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is easier to reproduce (e.g.: remote machine not available). After about 1 day, I get a usage of 300MB of memory. I have used .NET Memory Profiler tool to try to see where the leak is located. For all the leaky instances, I can see the following (I...
4
6076
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password"; scope.Path.Path=@"\\pc\root\cimv2";
23
4540
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
8529
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of each object within my JS app to help locate my problem? Thanks
3
5304
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". Anybody know anything about this? Does *Javascript* leak memeory, or does the *browser* leak memory?
7
5103
by: david wolf | last post by:
I have a problem that is used to test memory leak as follows, however, after each run of the program, if I am using the command "free" on the linux box, I did not see any difference about the usable memory. My questions are: 1) How to find out exact free memory that my program can use? 2) Use which command to do this (top, or free) 3) why it does not show memory leak in my case (I am using the linux command free) ...
7
15689
by: Ragnar Agustsson | last post by:
Hi all I have been wandering about the best way to sandbox memory leaks in 3rd party libraries when using them from the .Net framework. I have a 3rd party library, written in C++, that leaks a lot of memory but I still had to use it. 1. After using DLLImport and seeing the memory leak I tried to load and
22
9330
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a memory leak someplace. I can not detect the memory leak by running several reports by hand, but when I run tha app as a servrice and process few hundred reports there is significant memory leak. The application can consume over 1GB of memory where it...
0
8173
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8679
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.