Reputation: 11
I am learning to code in C. I came across the term 'memory leak'. So, I want to ask, if I wrote a simple program in C, in which malloc() is used and if I didn't free it (though I know freeing the dynamically allocated memory is a good programming practice). Will that memory leak would be there in the system permanently? Will the OS never use that memory again as it is sort of lost maybe?
Just consider the case where small amount of memory(100 bytes or so) is allocated, which we do while practicing. I'm asking this because I'm running the same program multiple times for debugging, are those memory leaks harmful?
Or the OS detects the memory leak and restore it?
Any help regarding the above and related topics is appreciated.
Upvotes: 0
Views: 317
Reputation: 223274
General-purpose operating systems are designed to protect against all sorts of issues caused by misbehaving programs. That includes managing memory. The operating system maintains its own records about what memory has been provided to each process, and it reclaims that memory when the process terminates (and no other process is using it, as occurs with various shared memory).
Special-purpose “embedded” operating systems might not provide this function.
Upvotes: 1