#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    21
    Rep Power
    0

    free() memory in C...


    Hi, guys....I have a quick question....
    let's say I have a C program...
    I malloc memory space in my code...

    do I need to free those memory before I exit the program....or those memory which I allocated during running will automatically be freed when the program terminates?...

    tks...
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    21
    Rep Power
    0
    I read this from the man page.

    After free() is executed, this space is made available for further allocation by the application, though not returned to the system. Memory is returned to the system only upon termination
    of the application.

    how about those memory I didn't free....will be return to the system after termination?
    Last edited by tmike; September 20th, 2003 at 02:46 AM.
  4. #3
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,111
    Rep Power
    1803
    Windows cleans up when a program terminates. But that is an OS issue not a C language issue. You should still free all allocated memory, it is generally considered good practice!

    Clifford.

IMN logo majestic logo threadwatch logo seochat tools logo