Singleton class memory leakage?

I think that whoever that wrote that tutorial didn't write this right.

I think that whoever that wrote that tutorial didn't write this right: self alloc init; Instead, it sould be: _sharedMySingleton = MySingleton allocinit; I hope it helps.

SharedMySingleton = self alloc init would work too. – Anders K Jan 28 at 11:45 yes I got it. Thanks for all replies........ – Srinivas Jan 28 at 12:10 self in the context of a class method is the class that received the message, which in this case would be MySingleton.It's usually better to write this as _sharedMySingleton = self alloc init; as Anders said.

That way the code would work correctly for subclasses, should that ever be necessary. – jlehr Jan 28 at 21:30.

You do not assign the allocation to a variable. Change it to this: +(MySingleton*)sharedMySingleton { @synchronized(self) { if (!_sharedMySingleton) _sharedMySingleton = self alloc init; } return _sharedMySingleton; } EDIT my typing was too slow, others have already replied :).

You probably deserve the accepted answer though, with your full snippet! – Dave Jan 28 at 11:39 @Dave thank you kindly dear sir :) – MiRAGe Jan 28 at 11:40.

It looks like when you return _sharedMySingleton, it will still be nil. And hence allocated the next time, too. You should try setting it when the alloc is done.

Self alloc init; --- is not assigned to the object.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions