DEVFYI - Developer Resource - FYI

You forget to call CloseHandle - will there be a memory leak?

Windows programming Interview Questions and Answers


(Continued from previous question...)

14. You forget to call CloseHandle - will there be a memory leak?

Well, yes and no. It is possible for a process to leak resources (such as kernel objects) while the process runs. However, when the process terminates, the operating system ensures that any and all resources used by the process are freed—this is guaranteed. For kernel objects, the system performs the following actions: When your process terminates, the system automatically scans the process’s handle table. If the table has any valid entries (objects that you didn’t close before terminating), the system closes these object handles for you. If the usage count of any of these objects goes to zero, the kernel destroys the object.

(Continued on next question...)

Other Interview Questions