Q:

CloseHandle necessary when using HeapDestroy?

I allocated an array of HANDLE on an Heap and then each handle is associated with a thread.
Once I'm finished with the work, do I have to call CloseHandle() on each of them before calling HeapDestroy()? Or does the latter call make the first useless?

A:

Always close a handle once you've finished with it - it is good practice. The Windows Kernel has tables which tracks assigned handles and who they are assigned to, so it will be in your best interest to remember to close them.
Handle leaks is also a thing which exist and it is when a caller requests for a handle but doesn't close it, and they pile up over a duration of time.
You can also occasionally cause other problems by not closing handles (e.g. sharing violations if you opened a handle to a file and denied sharing but you've kept the handle open when you no longer need the open handle).
To be precise though, handles are fake - the Windows Kernel translates them because it relies on an internal, undocumented and non-exported table which stores the real pointer address to a kernel object linked to that fake handle.

