Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Must I free allocated memory before the program exits?
Must I free allocated memory before the program exits?
✍: Guest
You shouldn't have to. A real operating system definitively reclaims all memory and other resources when a program exits; the system cannot afford to have memory integrity depend on the whims of random programs. (Strictly speaking, it is not even free's job to return memory to the operating system.) Nevertheless, some personal computers are said not to reliably recover memory unless it was freed before exiting, and all that can be inferred from the ANSI/ISO C Standard is that this is a ``quality of implementation issue.''
On the other hand, the C library free function rarely returns memory back to the operating system ), so calling free probably isn't the way to guarantee that an exiting program's memory is recovered by the system, anyway.
In any case, it can be considered good practice to explicitly free all memory--for example, in case the program is ever rewritten to perform its main task more than once (perhaps under a Graphical User Interface). On the other hand, there are programs (such as interpreters) that don't know what memory they're done with (i.e. what memory could be freed) until it's time to exit, and since all memory should be released at exit, it would be a needless, potentially expensive, and error-prone exercise for the program to explicitly free all of it.
2016-03-28, 1692👍, 0💬
Popular Posts:
How To Control Padding Spaces within a Table Cell? - XHTML 1.0 Tutorials - Understanding Tables and ...
If client side validation is enabled in your Web page, does that mean server side code is not run? W...
Can you prevent a class from overriding ? If you define a class as “Sealed” in C# and “NotInheritab...
Can you explain in brief how the ASP.NET authentication process works? ASP.NET does not run by itsel...
Can Java object be locked down for exclusive use by a given thread? Yes. You can lock an object by p...