我收到了錯誤消息,但不知道如何擺脫它。xcode,分析alloc錯誤
-- Method returns an Objective-C object with a +1 retain count (owning reference)
和
--Object allocated on line 46 is not referenced later in this execution path and has a retain count of +1 (object leaked)
線路AAA和bbb
+ (CustConf*) initEmptyCustConf {
CustConf* theObject = [[CustConf alloc] init];
theObject.ID = 0;
theObject.aAA= [[NSString alloc] initWithString:@""];
theObject.Number_Ndx = 0;
theObject.bBB = [[NSString alloc] initWithString:@""];
return [theObject autorelease];
}
ok,但爲什麼?(對不起,如果這是基本的) 來自[CustConf alloc] init的對象是否自動擁有一個retaincount爲1? – Franck
我不確定,你能否顯示CustConf.m文件的代碼?然後我可以看到,但只是分配應該給你一個保留計數,然後autoreleasing(這是正確的事情)將在未來某個時候。所以這都是正確的。它必須是'CustConf'類的'alloc'或'init'方法中的東西。 – chown
更多關於theObject.aAA = @「」與theObject.aAA = [[NSString alloc] initWithString:@「」] 即使我需要設置一個值,不需要分配它嗎? [[NSString alloc] initWithString:@「My int value」]; – Franck