I understand that memory leaks are undesirable, but I don't know all the ways they can be generated. Is there some way to detect them programmatically?
You can generate them by allocating memory with NEW or a windows function like GlobalAlloc and then forgetting to free it, or assigning its pointer somewhere else. There's not an easy way to detect them unless you build your own garbage collecting system and allocate all variables through it.