-
August 8th, 2009, 12:27 PM
#1
How to trace memory leaks
Hi,
I'm having some problems with detecting the cause of memory leaks in my code.
The problem here is that at the end of a debug I get a memory dump of all detected leaks, but line in the code where the memory was assigned is not provided.
So for example a dump will look like this:
Detected memory leaks!
Dumping objects ->
{78} normal block at 0x001910D0, 32 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The thread 0x1158 has exited with code 0 (0x0).
The program 'C:\SOFTWARE\memoryleaks\Debug\memoryleaks.exe' has exited with code 0 (0x0).
But not the location in the code.
Is there some way of getting this information?
Thanks!
-
August 8th, 2009, 01:36 PM
#2
Re: How to trace memory leaks
Add this at the beginning of source (.cpp) file
Code:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
-
August 8th, 2009, 01:47 PM
#3
Re: How to trace memory leaks
Got that one already.
But that only works for things such as:
double * d;
d=new double;
but not for
double * d;
d=(double *)calloc(4,sizeof(double));
It's the second one where I suspect my memory leaks are, and the ifdef DEBUG line doesn't work here.
-
August 8th, 2009, 02:32 PM
#4
Re: How to trace memory leaks
Not a help with memory leak, but why are you mixing C and C++ memory allocations?
-
August 8th, 2009, 05:11 PM
#5
Re: How to trace memory leaks
Originally Posted by rmirani
Got that one already.
But that only works for things such as:
double * d;
d=new double;
but not for
double * d;
d=(double *)calloc(4,sizeof(double));
It's the second one where I suspect my memory leaks are, and the ifdef DEBUG line doesn't work here.
Then replace that calloc() line with operator "new".
Heck, even better -- replace that whole thing with std::vector<double>. Then you don't worry about memory leaks at all.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|