Visual Studio 6 (sp6) producing memory leaks?

Started by
7 comments, last by persil 18 years, 10 months ago
Greetings! I was playing arround with memory leak detection in Visual C++ 6. Micro$oft has build in a memory leak detector which can be included as: #include <crtdbg.h> int main(void) { _CrtDumpMemoryLeaks(); return 0; } It only works in debug mode. When running that program in visual C++ 7 or 7.1 it works fine, but in Visual C++ 6 it throws me memory leak report?! Why?! The program is empty!!! Another demo: int main(void) { //sorry error:int new; new int; _CrtDumpMemoryLeaks(); return 0; } In Visual C++ 7/7.1 it produces 4 byte memory leak (one int) but in visual C 6 (on all available service packs) it throws a report. What is going on? Does anoyne have a clue? [Edited by - Samurai Jack on May 25, 2005 4:56:20 AM]
Advertisement
I think you are mistaken somewhere. The first example gives no memory leaks at all in MSVC 6.0. The second example will not compile because 'new' is a reserved keyword. If declared with a different name it does not give a memory leak (correctly) because the memory is allocated statically and released immediately when main() ends.

Greetz,

Illco
I get memory leaks all the time in Visual C++ 6 Enterprise with SP6 with souch simple programs. Maybe someone else could try too?

It works fine in VS 7 or VS 7.1 (all licensed and updated).

There was an error:
int new;
should be:
new int; //memory leak

You should run the samples with (Start Debug->GO)=F5 not CTRL+F5!
Quote:
should be:
new int; //memory leak

With this it reports the memory leak in MSVC 6.0 like it should.

Quote:
You should run the samples with (Start Debug->GO)=F5 not CTRL+F5!

Trust me, I know. Yes, maybe someone else can try.
Ilco is quite right. I tried, too. And, as he says, the MSVC leak detector works as it should.
Kippesoep
yeah, quite right.

"new int" is a leak.

int * ptr = new int;
delete ptr;

isn't
This was just a demonstration to produce a 4 byte memory leak.
So "new int;" should produce 4 byte memory leak which was supposed to be reported.
I get a report like this:

int main() { _CrtDumpMemoryLeaks(); return 0; } :


Quote:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Detected memory leaks!
Dumping objects ->
{41} normal block at 0x003208E8, 33 bytes long.
Data: < C > 00 43 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{40} normal block at 0x00320880, 40 bytes long.
Data: < C > EC 11 43 00 16 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The thread 0x2DC has exited with code 0 (0x0).
The program 'c:\brisito7\Debug\brisito7.exe' has exited with code 0 (0x0).


int main() { new int; _CrtDumpMemoryLeaks(); return 0; } :

Quote:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Detected memory leaks!
Dumping objects ->
{42} normal block at 0x00320950, 4 bytes long.
Data: < > CD CD CD CD
{41} normal block at 0x003208E8, 33 bytes long.
Data: < C > 00 43 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{40} normal block at 0x00320880, 40 bytes long.
Data: < C > EC 11 43 00 16 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The thread 0x48C has exited with code 0 (0x0).
The program 'c:\brisito7\Debug\brisito7.exe' has exited with code 0 (0x0).


The first block is 4 bytes long, which is ok, because i forced it to be there. But what about the 33 bytes long chunk, which appears in both applications?
The version I'm using is: Visual Studio 6 Enterprise Edition (SP6).
Quote:Original post by Samurai Jack
This was just a demonstration to produce a 4 byte memory leak.
So "new int;" should produce 4 byte memory leak which was supposed to be reported.
I get a report like this:

int main() { _CrtDumpMemoryLeaks(); return 0; } :


Quote:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Detected memory leaks!
Dumping objects ->
{41} normal block at 0x003208E8, 33 bytes long.
Data: < C > 00 43 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{40} normal block at 0x00320880, 40 bytes long.
Data: < C > EC 11 43 00 16 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The thread 0x2DC has exited with code 0 (0x0).
The program 'c:\brisito7\Debug\brisito7.exe' has exited with code 0 (0x0).


int main() { new int; _CrtDumpMemoryLeaks(); return 0; } :

Quote:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Detected memory leaks!
Dumping objects ->
{42} normal block at 0x00320950, 4 bytes long.
Data: < > CD CD CD CD
{41} normal block at 0x003208E8, 33 bytes long.
Data: < C > 00 43 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{40} normal block at 0x00320880, 40 bytes long.
Data: < C > EC 11 43 00 16 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The thread 0x48C has exited with code 0 (0x0).
The program 'c:\brisito7\Debug\brisito7.exe' has exited with code 0 (0x0).


The first block is 4 bytes long, which is ok, because i forced it to be there. But what about the 33 bytes long chunk, which appears in both applications?
The version I'm using is: Visual Studio 6 Enterprise Edition (SP6).

Its probably just global memory that you're not responsible for. Calling _CrtDumpMemoryLeaks() at the end of main() only gets you so far. As I recall [its been a while since I used this], the following code is a better solution:
int main(){_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);new int;}

That'll cause the report to be after all the global memory has been released, so all you've got left is actual leaks.

*edit:
Got my test running right...it seems to work as intended. Note, I never see the stuff you report, possibly due to my use of a later version of the compiler/libraries.
class NoLeak{public:    NoLeak() {p = new int;}    ~NoLeak() {delete p;}    int* p;};int main(){    NoLeak this_wont_leak;    int* this_will_leak = new int;    _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);    _CrtDumpMemoryLeaks();}

Result:
Detected memory leaks!Dumping objects ->{46} normal block at 0x00322D60, 4 bytes long. Data: <    > CD CD CD CD {45} normal block at 0x00322D20, 4 bytes long. Data: <    > CD CD CD CD Object dump complete.Detected memory leaks!Dumping objects ->{46} normal block at 0x00322D60, 4 bytes long. Data: <    > CD CD CD CD Object dump complete.


CM
Using a memory leak detector tool, something happened to me once. I opened an application which I knew didn't leak. And there was always a couple of bytes leak reported. I wsa wondering what it is, since there was no usable information. Then , I retried the same test later, and the leak was gone. So, it may just mean that sometimes, something that is external to your application might interfere with the detection.

This topic is closed to new replies.

Advertisement