csigint

Does Keyboard Interrupt free all pointers, heap memory, file handles, etc


I have some code that gets file handles (and uses them) and allocates memory to the heap. If I were to press ctrl-c in the terminal that it is running in, and the code has not yet progressed to the part where it frees the memory and closes the handles before safely exiting, will they be still be freed, or do I need to create my own handler as shown in this post?


Solution

  • When you are executing as a user in a normal modern general-purpose multi-user operating system, the operating system will reclaim all resources when the program terminates regardless of the means by which the program terminates. That is a principal job of the operating system. It operates the system.