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?
Printable View
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?
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.
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.
www.flipcode.com has a good thread on memory leak detection.
I found:
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.PHP Code:
#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
We all hope ;)
I hate memory leaks...they're so annoying - especially the delete rather than delete[] kind.
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.
The files are automatically closed when the object goes out of scope.Code:#include <fstream>
using namespace std;
void somecode() {
ofstream OutFile("filename.ext");
if(OutFile.fail() // Didn't work
return;
OutFile << "Hello: " << 5 << '6' << endl;
}
I don't get what you mean with (a) :confused:
a) I mean it say like thread 0xFFF57315 exited with code -1. How do I know what thread 0xFFF57315 was?
b)Thanks
It might be the thread ID or thread handle (the value returned from CreateThread).