IOS: saving a shared instance

I use a common instance of a singleton class in a function, what do I need to do retainfor an object? A few examples that I have seen, do it: AVAudioSession *session = [[ AVAudioSession sharedInstance] retain];and some simply do: AVAudioSession *session = [ AVAudioSession sharedInstance];. I’m sure that somewhere there is a rule that should tell me what to do, but I just don’t know that.

+3
source share
3 answers

You are right, there are rules that tell you what to do . These are the same rules that you use throughout Cocoa Touch. Singleton customers should not care that the object they are using is single, and they should definitely not rely on singleton to avoid common memory management conventions.

, , , , , . , , , - ( ), . , - .

+4

, . singleton , , , , . , , , . , , , , . , , sharedInstance .

+7

sharedInstances, singleton.

+1

All Articles