2 ms·
When you're using malloc, it's up to you to call free() when you want to release memory that you know is no longer needed by your program. The only time the ope
by greenyoda 6y ago
When you're using malloc, it's up to you to call free() when you want to release memory that you know is no longer needed by your program. The only time the operating system will free memory without being asked is when your process exits (which, in the case of a long-running program like a web server, could be never).
In contrast, a garbage collector periodically detects that memory is no longer being used (e.g., an object that no existing object has pointers to), and automatically frees it. The programmer is not required to do anything to make this happen.