See the exit()
documentation . In fact it does some cleaning in the when it is called, it can even register some things to be executed when it is called. If you need something to run you should call it. But remember that the application may break before and it will not be called even if you want.
Outside this extra flame she does not do anything too 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 it is, everything will be released.
If you have open connections, it is the job of each service to realize that you have nothing more to communicate with and shut down. Of course, it's all controlled by the operating system in some way and it will shutdown somehow, even if not in the ideal way.
By default, understand that whatever you allocate must deallocate as early as possible, but never before it is possible, and every externally acquired resource is released (eg connections). A code that does not make these releases early is a wrong code by definition, even when it does not cause error. All malloc() ou algo semelhante deve ser pareado com um
free () '.
So C programmers know that, in general, you should not allocate memory in another function, the allocation takes place the first place it needs and so the person knows that he needs to give
free()
there, even 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 full commitment to it. Go to another language if you want ease to manage memory. Because it complicates a lot when it is not possible to maintain this simple control of allocate / deallocate within the function, and it has several cases like this, where allocation depends on the lifetime of an object and not on the function. So one of the best inventions of computing was the garbage collector.
So it is advisable to deallocate as soon as possible and rarely need to call exit()
. She does not do what you think.