简体   繁体   English

目标 C: Memory Class 方法中的泄漏问题

[英]Objective C: Memory Leak issue in Class Method

I am hitting the memory leak warning message as seen in the screenshot below.我正在点击 memory 泄漏警告消息,如下面的屏幕截图所示。

在此处输入图像描述

I need some advise on how I can resolve this memory leak.我需要一些关于如何解决此 memory 泄漏的建议。 Can I just do a [self release] at the end of the method?我可以在方法结束时做一个 [自我释放] 吗?

You are not assigning the object returned to _sharedUserStockInfo so you are losing reference and leaking.您没有分配返回给_sharedUserStockInfo的 object,因此您正在丢失参考和泄漏。 Over that _sharedUserStockInfo will remain nil and method will return nil too.在那个_sharedUserStockInfo将保持为nil并且方法也将返回nil

+(UserStockInfo*)shareduserStockInfo{

     @synchronized([UserStockInfo class])
     {

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

     return nil;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM