簡體   English   中英

調用者此時尚未擁有的對象的引用計數的不正確減量用於保留屬性

[英]Incorrect decrement of the reference count of an object that is not owned at this point by the caller For retain property

我創建了一個帶有保留屬性的NSString fName屬性,並合成了該屬性。 我在viewDidLoad上初始化了該屬性。

我的實際概率是,我使用了[self.fName版本]。 此示例工作正常,但靜態分析器將此行顯示為錯誤“調用者此時尚未擁有的對象的引用計數不正確地遞減”。

參考代碼:

@interface ViewController : UIViewController

@property(nonatomic,retain)NSString *fName;

@end

@implementation ViewController
@synthesize fName;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.fName =@"Hello";

    [self.fName release];//Analyzer showgin error here.

}
---------
------
end

那里不需要釋放。 您不分配/初始化任何東西。 如果您正在執行以下操作:

self.fName = [[NSString alloc] initWithString:@"Hello"]; 

那么您必須釋放self.fName。

根據經驗,numberOfReleases = numberOfAlloc。

現在,黃金法則,USE ARC :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM