See the function documentation exit()
. In fact it does some cleaning on when it is called, it can even record some things to be performed when it is called. If you need something to be executed you should call it. But remember that the application may break before and it will not be called even if you want to.
Other than this extra flame, she doesn’t do much. Your application does not own the memory allocated by it and the operating system will release everything at the end of the process, so no matter where everything will be released.
If you have open connections it is the function of each service to realize that there is nothing else communicating with it and closing. Of course, it’s all controlled by the operating system somehow and it will shut down somehow, even if not in the optimal way.
By default understand that everything you allocate, should displace as soon as possible, but never before it is possible, and every resource acquired externally is released (connections for example). A code that does not make these releases early is wrong code by definition, even when it does not cause error. All malloc()
or something similar should be paired with a free()
.
So C programmers know that, in general, they should not allocate memory in other functions, the allocation takes place the first place they need and so the person knows they need to give a free()
there, including with control to have an exit from this function for only one place. Managing memory in C is extremely difficult and so only use this language if you have total commitment to it. Go to another language if you want ease to manage memory. Because it complicates a lot when you can’t keep this simple control of allocating/dislocating within the function, and it has several cases like this, where the allocation depends on the lifetime of an object and not the function. So one of the best computer inventions was the garbage collector.
So it is recommended to relocate as soon as possible and rarely need to call exit()
. She doesn’t do what you think.