Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C: Memory Leak issue in Class Method

I am hitting the memory leak warning message as seen in the screenshot below.

enter image description here

I need some advise on how I can resolve this memory leak. Can I just do a [self release] at the end of the method?

like image 673
Zhen Avatar asked Jul 02 '11 16:07

Zhen


2 Answers

You are not assigning the object returned to _sharedUserStockInfo so you are losing reference and leaking. Over that _sharedUserStockInfo will remain nil and method will return nil too.

like image 115
Deepak Danduprolu Avatar answered Sep 23 '22 19:09

Deepak Danduprolu


+(UserStockInfo*)shareduserStockInfo{

     @synchronized([UserStockInfo class])
     {

         if(! _sharedUserStockInfo)
             _sharedUserStockInfo= [[self alloc]init];
         return _sharedUserStockInfo; 
     }

     return nil;
}
like image 25
Vijay-Apple-Dev.blogspot.com Avatar answered Sep 22 '22 19:09

Vijay-Apple-Dev.blogspot.com