I see alot of tutorials using malloc, calloc for allocating memory space, but they are not freeing up the memory.
Shouldn't free be used after malloc or calloc is been used?
I see alot of tutorials using malloc, calloc for allocating memory space, but they are not freeing up the memory.
Shouldn't free be used after malloc or calloc is been used?
It's generally a good habit to free memory after you're done with it. So you're more likely to do the right thing when it actually matters.
If your program is short-lived, and mallocs what it needs at the start, there is seldom any need to call free.
Question 7.24
But if you're writing a long running server or daemon which is expected to run indefinitely, you need to make sure you free everything when you're done with it.
Otherwise, you'll slowly leak memory until the OS eventually kills the program.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.