As comments said, when the process is about to exit,
All this memory management is pointless. The process is exiting. All that memory will be freed when the address space is destroyed. Stop wasting time and just exit already.
This is also mentioned in Terminating a Thread:
- Any resources owned by the thread, such as windows and hooks, are freed.
By the way, if you just change the icon, you need to free the previous one.