Recently I am following the tutorials on rastertek and find that they suggest use a Shutdown()
method for cleaning up instead of the class own destructor.The reason they mention is that the destructor is not guaranteed to be executed when calling some unsafe function like ExitThread()
.
However, I doubt if that method would get executed when even the destructor cannot be called. Indeed you can always call Shutdown()
before you call ExitThread()
but why not the same for the destructor? If I can do something before calling ExitThread()
, I can certainly call the destructor as well.
Isn't placing the clean up code in the destructor more or less safer than using another method to do the trick? I know that releasing some vital resources like closing a file may need this separate method to do the trick. But are there any reasons other than that since this does not seem to be the case in the tutorials?
For the record, I know there is a similar question out there. But that one got no answer.