Howdy, Stranger!

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

Categories

Freeing dynamic memory

macmoodmacmood Member Posts: 11

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

  • DariusDarius Member Posts: 1,666
    :
    : 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

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _ ( http://forcoder.org ) free ebooks and video tutorials about { Scratch PHP R C++ Perl JavaScript Go PL/SQL C Delphi Visual Basic .NET Python Swift MATLAB Objective-C Java Ruby C# Assembly Visual Basic Lua Rust D Apex Kotlin Fortran Alice Scheme Julia Bash Scala FoxPro ABAP LabVIEW Transact-SQL Erlang Ada COBOL Lisp Clojure Logo F# ML Awk VBScript Prolog Dart SAS Hack Crystal } ___________

Sign In or Register to comment.