Can Singleton Classes be "truly indestructible"?
Jul 4, 2016 at 2:46am UTC
When I say truly indestructible, I'm referring to the class object not getting destroyed until the machine is turned off. Is this true?
I read in a Stack Overflow post, that there are "2 varieties of singletons with respect to destructibility:
1) Destructible (They die when the application does)
2) Indestructible (They die when the machine does)"
I'm having trouble understanding how an object stays alive even when the application is shutdown.
This is an example of a singleton class design pattern I use all the time, I got it from an SDL book:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class UI {
public :
static UI *Instance() {
if (m_instance == 0) {
m_instance = new UI();
return m_instance;
}
return m_instance;
}
private :
static UI *m_instance;
UI(){};
~UI(){};
};
source:
http://stackoverflow.com/a/15733545
Last edited on Jul 4, 2016 at 2:47am UTC
Jul 4, 2016 at 3:05am UTC
When I say truly indestructible, I'm referring to the class object not getting destroyed until the machine is turned off. Is this true?
No.
Jul 4, 2016 at 3:44am UTC
Thanks cire, that's what I thought. Not sure where the poster from Stack Overflow got that idea.
Jul 4, 2016 at 3:53am UTC
but then there should be a way to create a truly indestructible stuff?
Jul 5, 2016 at 3:28am UTC
I believe you're misunderstanding how programs are developed. Basically you want to make it a background process which is always running, started upon boot.
Topic archived. No new replies allowed.