Thread: Is memory released after program terminates?

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    1

    Is memory released after program terminates?

    I have a quick question regarding memory. After running a c++ program, is all of the memory used by the program released after the program terminates? How can I make sure that it is released?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Yes. Well -- this is not part of the standard, it is up to the operating system. But I think all modern operating systems do take care of that.

    [edit] this is not to say you shouldn't bother with clean-up -- it's better to be in that habit than being "cleverly" lazy
    Last edited by MK27; 06-09-2010 at 11:44 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    But you should not rely on this. It's considered good practice to clean up after yourself.
    The easiest way is to make use of available constructs such as std::vector, std::list, etc. And if you really need to use dynamic memory, we have smart pointers as our disposal, such as std::shared_ptr (or std::tr1::shared_ptr).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Question 7.24

    If you consider that your module may become part of a larger program at some point, then making sure everything is nice and tight is a good idea.

    Plus it's also good practice
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory allocation overflow in c program
    By bassam_fci in forum C Programming
    Replies: 6
    Last Post: 05-19-2009, 03:35 PM
  2. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  3. Program uses a lot of memory and doesnt exit properly
    By TJJ in forum Windows Programming
    Replies: 13
    Last Post: 04-28-2004, 03:13 AM
  4. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM