Does Linux automatically re-claim all memory used by an applications immediately?
If so then should the application really bother about freeing all memory before exit?
Is it really worth to call the destructor of every class in a multi-threading application before making a call to exit(0)?
If Linux always re-claims all memory used by an application immediately, then memory leaks are only the dangling pointers which the application has created and that too only it its lifetime.
No, but yes in the sense that you’re implying. All virtual memory belonging to the process are released. Frames that aren’t shared are made available to other processes.
Yes, for several reasons:
There are situations that could arise when not freeing memory is what you want, generally these will be performance related, and only specific to those situations.
This is pretty much the same as the last question. Also note that not releasing resources from third party, and OS libraries is effectively the same as not freeing memory.
Yup. The only time this theory breaks down is when resources held are global, and don’t go away at process termination. Shared memory, poorly designed third party libraries, temporary files etc. are examples of these.