Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Where to release the object in Singleton class? (http://www.go4expert.com/forums/release-object-singleton-class-t14010/)

BS Dahiya 18Sep2008 16:10

Where to release the object in Singleton class?
 
Where to release the object in Singleton class? Should we go destructor(Private) or any other static member function? I mean , what is the best solution?

xpi0t0s 19Sep2008 13:03

Re: Where to release the object in Singleton class?
 
Not the destructor, because deleting the object calls the destructor and that'll be recursive.
Normally you would implement a get method which creates the object if it doesn't exist, then returns a reference to itself, and a release method which deletes the object if there are no references left. These are both static functions. If it's a global object of which there will always be one instance then get just returns a reference and release doesn't need to exist.

BS Dahiya 23Sep2008 14:11

Re: Where to release the object in Singleton class?
 
Thanks a lot. It is really fruitful.I got the idea,
Regards,
BSD


All times are GMT +5.5. The time now is 12:40.