ANONYMOUS wrote:
> Do we need to free absolutely everything that we've malloc'd after the program finishes syncing and is about to exit? It's my understanding that when a process terminates, it's memory is freed automatically so it's sort of unneeded unless you wanted to extend the program, even if it might be bad practice.
Your understanding is correct, a terminating process's memory is returned to the OS for other processes (existing and new) to use.
So any allocated memory use in/for long-term data structures need not be freed.
However, as a general practice, you should try to free memory that you only require for a short time.
For example, if you allocate memory at the top of a loop, and use it only within the loop, then you should free it at the bottom of the loop, rather than letting it become disconnected garbage in your program:
for(int i=0 ; ....) {
char *p = malloc(...);
// use p's memory
free(p);
}