Join Now

This page was last modified 13:28, 8 May 2007.

Talk:How to implement a singleton class in Symbian OS

From Forum Nokia Wiki

When implementing singleton it's not enough to simply work out the instantiation, you also have to consider the destruction. Seems that it has been ignored here.

The destructor of the singleton class should not be public. The caller should not be able to delete the instance directly. The whole point of a singleton pattern is to share an instance of a class which means you have to be careful with its lifespan. An object that uses the singleton instance cannot be allowed to simply delete it when it is done with it because there might be another object still using it.

So the destructor should be made private. If the singleton instance is supposed to be deleted when it is no longer used, you should implement a simple reference counting mechanism and for example a static Release() function to decrement the count and delete when it reaches zero.

There are other ways to handle the destruction if singletons, this was just an example. The point was that you need to think about it.

- Marko

 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX