Re:Ask HN: What is the funniest bug you encountered?
by AnimalMuppet on Monday November 27, 2017 @05:03PM
(#15791963)
I've actually used a destroyInstance method, for testing. But if you do that, first, nobody can hang on to the pointer they get from getInstance, ever, anywhere in the entire code base. And second, the instance has to be a pointer (so that destroyInstance can delete it), and destroyInstance has to NULL the pointer. Then getInstance has to create a new instance if the pointer is NULL.
It can be done, but if anybody ever calls destroyInstance in production code, well, I question their approach...
Making the singletons in shared objects, each one gets it's own. Adding a destroyInstance method.