Results 1 to 10 of 10

Thread: Memory Leaks

  1. #1

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024

    Memory Leaks

    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?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    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.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    www.flipcode.com has a good thread on memory leak detection.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I found:

    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 
    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.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    We all hope

    I hate memory leaks...they're so annoying - especially the delete rather than delete[] kind.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    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.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    #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)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    a) I mean it say like thread 0xFFF57315 exited with code -1. How do I know what thread 0xFFF57315 was?

    b)Thanks
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It might be the thread ID or thread handle (the value returned from CreateThread).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width