Freeing dynamic memory


Just a question about dynamic memory:

Should I even bother calling free() on malloc()'ed data if the only
place I can give back the memory is on program exit? I thought the OS would clean up all the memory my process is taking on the stack when the process terminates. If this is the case then free()ing at the
end of a program would be useless, correct?

Thanks in advance.

Comments

  • :
    : Just a question about dynamic memory:
    :
    : Should I even bother calling free() on malloc()'ed data if the only
    : place I can give back the memory is on program exit? I thought the OS would clean up all the memory my process is taking on the stack when the process terminates. If this is the case then free()ing at the
    : end of a program would be useless, correct?
    :
    : Thanks in advance.
    :

    The OS MAY clean up memory, but the C/C++ standards don't cover operating systems, you can't make that assumption. Anyway you should be getting into the habit of freeing memory you allocate.

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion