lovecreatesbeauty wrote:
When I allocate memory use malloc() and forget to call a corresponding
free(), does this allocated memory lose forever after program exits
(Can i regard it same as process exits? )?
The standard does not specify this.*
Or will the allocated memory be released after program exits?
On modern desktop operating systems, yes. On more specialised
operating systems, perhaps not.
You should structure your code so that you can easily deallocate
any and all dynamic objects. However, many programs avoid actually
doing the deallocation on program exit because, one some systems,
it can needlessly cause the system to thrash.
However, the more complicated your program, the more sense it makes
to deallocate memory. If system resources are tied to given memory
allocations, then the deallocation routines in your code can (and
should) untie/close those system links as the same time.
So, the choice is yours.
* Certainly not in any way that a strictly conforming program could
ever tell.
--
Peter