+ 1

What happens when dynamically allocated memory is not freed?

In C programming, memory can be dynamically allocated using functions like malloc() and calloc(). After finishing to use such memory, it can be freed using free() function. What happens if free() function is not used? Will such memory get freed itself after the program terminates or will it remain for forever?

30th Mar 2019, 12:30 AM
Gopal
Gopal - avatar
2 ответов
+ 6
It will be freed after the program terminates but not while the program is running, so if that memory is no longer used while a long-term program is running like a high availability server, you have a memory leak. Unlike Java etc. C has no automatic garbage collector to free unused memory automatically.
30th Mar 2019, 12:53 AM
Sonic
Sonic - avatar
+ 1
Okay I got it. Thanks for the answer!!!
30th Mar 2019, 1:23 AM
Gopal
Gopal - avatar