View Full Version : Intentional memory leakage. Always a misuse?

07-06-2015, 03:32 PM
I guess it's more of a general question about processes in an operating system, but it also fits into here, I think.

Suppose I run a program that allocates heap memory, never frees it, but then exits.
Correct me if I'm wrong, but whenever a process exits, the OS deallocates (almost) every memory chunks that are associated with it; including its heap, stack, and PCB (https://en.wikipedia.org/wiki/Process_control_block). So, in that case, harm can only be done by programs that 'run in background' for a long period of time, and consume memory they do not actually use or need.
Putting aside the risk of acquiring a bad habit, in terms of memory usage, what is the harm of not freeing heap memory in programs that are designated to perform a specific (small) task?

I mean, for something as simple as:

int main(int argc, char* argv[]) {

// do some specific task that consumes heap memory

return 0;

07-06-2015, 05:53 PM
>> what is the harm ...
You risk acquiring a bad habit.

That aside, a modern OS will "reclaim" the memory cleanly.


07-06-2015, 09:45 PM
If you do not know when to free allocated memory and leave it upto OS to clean after you - in most cases it means your program architecture has some basic flaws that in big project will make your software unmanageable.

07-07-2015, 01:40 AM

I can't speak much for the risk beyond what you've already said, but I'll tell you that I assume no resources are used with care when seeing one resource used without care.