PDA

Click to See Complete Forum and Search --> : Memory Leaks


Technocrat
Jul 3rd, 2001, 10:21 AM
After my program is done running in debug mode, the debug window shows 2 threads that have exited with -1 (0xFFFFFFFF). I believe that means that they have memory leaked. Anyone know how to track down those nasty things?

parksie
Jul 3rd, 2001, 11:01 AM
One method I use is to do a search to count all the occurences of new, and the occurences of delete, and make sure they're the same number.

However, I don't think a thread returning -1 means there's a memory leak - I think it signifies some other kind of failure.

Technocrat
Jul 3rd, 2001, 11:07 AM
Thats the first thing I checked.

I used the C++ debug routines to check on memory leaks and it did not seem to trigger, so maybe the -1 is not a leak.

parksie
Jul 3rd, 2001, 11:10 AM
www.flipcode.com has a good thread on memory leak detection.

Technocrat
Jul 3rd, 2001, 11:29 AM
I found:



#ifndef NDEBUG

int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); // Get current flag

flag |= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit

_CrtSetDbgFlag(flag); // Set flag to the new value

#endif



and added it to my WinMain and it works when I turn off my delete[]. But it did not detect any leaks on my program regularly, so there must not be a problem....I hope.

parksie
Jul 3rd, 2001, 11:31 AM
We all hope ;)

I hate memory leaks...they're so annoying - especially the delete rather than delete[] kind.

Technocrat
Jul 3rd, 2001, 11:55 AM
Ok this is still bugging me

a) How can I tell what the threads are assigned to?
b) Can you quickly give me the code to write to a simple text file I dont want to have to go look it up.

parksie
Jul 3rd, 2001, 12:07 PM
#include <fstream>
using namespace std;

void somecode() {
ofstream OutFile("filename.ext");

if(OutFile.fail() // Didn't work
return;

OutFile << "Hello: " << 5 << '6' << endl;
}The files are automatically closed when the object goes out of scope.

I don't get what you mean with (a) :confused:

Technocrat
Jul 3rd, 2001, 12:14 PM
a) I mean it say like thread 0xFFF57315 exited with code -1. How do I know what thread 0xFFF57315 was?

b)Thanks

parksie
Jul 3rd, 2001, 12:20 PM
It might be the thread ID or thread handle (the value returned from CreateThread).