Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But that unique instance is presumably referenced by other objects which may want to use it as part of their own shut down logic, at which point it might no longer exist. (And things get only worse in the presence of threads.)


Sorry I read it again (the first time I was reading it on my phone) and I thought we were discussing about Meyers singleton:

Singleton & theSingleton() { static Singleton instance; return instance; }

Which in the proper context is perfectly fine.

This is wrong:

class myclass { // can have state // ... public static myclass m = new myclass(); // globally accessible static instance, which can have state }

and the first link itself explain why.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: