Goal C: Memory leak problem in class method

I click on a memory leak warning as shown in the screenshot below.

enter image description here

I need to advise how I can solve this memory leak. Can I just do [self release] at the end of the method?

+4
source share
2 answers

You do not assign the object returned to _sharedUserStockInfo to lose the link and the leak. In this case, _sharedUserStockInfo will remain nil , and the method will also return nil .

+6
source
 +(UserStockInfo*)shareduserStockInfo{ @synchronized([UserStockInfo class]) { if(! _sharedUserStockInfo) _sharedUserStockInfo= [[self alloc]init]; return _sharedUserStockInfo; } return nil; } 
+3
source

All Articles