Mistakes/questions in singleton example in book "Cracking the coding interview"?
<p>On page 259 of the book Cracking the coding interview a templated singleton in C++ is given (I don't want to post all the code in case its copy righted). </p>

<p>The question was to implement a singleton as a template, and with the assumption of a class called Lock make sure its thread safe and exception safe.</p>

<p>The answer is as you might expect for a singleton using the  double locking technique with the Lock object having an acquire()/release() pair.</p>

<p>However the class has no destructor. Is this a mistake or not? If it had a destructor, as the class instance member is static the destructor would only get called at termination of the program, and if the program is terminating any allocated memory would get freed up back to the system anyway. Or would it? Are there instances where this couldn't happen and the singleton not having a destructor therefore leads to a leak?</p>

<p>Secondly the question says make the singleton exception safe. The singleton object is created with a new that isn't caught, and the Lock object is static, therefore is this actually exception safe? If there is no memory for the creation of the singleton then new with throw an exception, but as the Lock object is static there's no way for its release() method to be called and hence its never called?</p>
