Is it advisable to have multiple singletons in an iOS App?

I have read several articles discussing pros an cons about singleton patterns. But I would like to know:

Is it advisable to have multiple singletons in an iOS App?

what are the pros and cons...?

Currently I am having only one singleton globally and holding strong references of other necessary properties including custom composite classes. But the idea sounds something strange for me for an example, accidentally I can create several instance of a custom composite class which I don't want.

Answers


You should have as many singletons as you need. Take a look at Cocos2d - it contains a fair amount of them: CCDirector, CCTextureCache, CCSpriteFrameCache and so on. There's no limit on singletons, say 5. If it's convenient for you to have one single center class for a certain kind of operations (like accessing network or a database or whatever) and you never need a second instance of this class then feel free to make it a singleton.


It depends on your requirement. You can have multiple singleton classes or objects.

The singleton object will be alive till your application quits. For memory managing concern, it'll be very difficult if you have multiple singleton objects(You can't release these singleton objects, when a memory warning raises).


Need Your Help

Errors when using 4 yaxis

javascript jquery jqplot

I am trying to create a chart that has 4 unique yaxis. When running, the FireFox error console reports this error:

Extend inherited prototype method in Javascript

javascript inheritance methods prototype extend

I have some classes (constructors) that are related as "parent-child":