Thread: Program crashes and memory leaks

  1. #1
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582

    Program crashes and memory leaks

    This is just out of curiousity about program crashes (any crash such as the "the application has encountered a problem and needs to close" message where you send an error report to Microsoft, or the "unhandled exception" thing) and memory leaks and various scenarios. What about when an infinite loop is encountered prior to reaching these 3 cases?

    1. Let's say that, somewhere in my code, I have an fopen instruction and while supposedly reading the file that is successfully opened, the program crashes before it gets to the fclose. Will the result due to the crash be the same as if fclose was never used in the program?

    2. Let's say you have a pointer pointing to 32 MB's worth of data (or something) and the program crashes before the "free" instruction is run across. Will there be a memory leak as if free was never called due to the program crashing?

    3. What about other things like this such as using UnregisterClass in Windows programs (of which frees the memory)?
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    On closing process (due to regular exit or crash) Windows SHOULD release all resources equired by the process - it means - close all opened handles, files, free memory etc...

    In a real life - some resources are still marked as used so you have problems restarting the application till you restart windows... For example I had problems using COM-ports after application crash (so the ports were not closed properly by the application)...

    Some files are marked as opened and cannot be deleted after crash till restart... It is very hard to check that really no memory leaks are there after crash, but in my expirience if they exist - they are not as big as 32MB - I cannot see the difference (between memory usage before application start and after it has been crashed) using TaskManager...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. funcion runs 14 times, then program crashes
    By happyclown in forum C Programming
    Replies: 9
    Last Post: 03-03-2009, 11:58 PM
  2. program crashes + fscanf() question
    By happyclown in forum C Programming
    Replies: 27
    Last Post: 01-16-2009, 03:51 PM
  3. What the hell!? Crashes and memory leaks?
    By pobri19 in forum C++ Programming
    Replies: 3
    Last Post: 09-26-2008, 05:45 AM
  4. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  5. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM