2011-04-29 38 views
0

我運行分析器,發現一些警告,我無法與代碼中的行關聯。我不知道如何處理它們。點擊它們會將我帶到編輯器中的正確文件,但分析器彙總結果告訴了我很多。我不知道它們各自所指的是什麼,並且逐行執行代碼並不是富有成效的(我不知道我在找什麼)。沒有詳細信息/行號的XCode分析儀警告

Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected 

Incorrect decrement of the reference count of an object that is not owned at this point by the caller 

Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected 

Object sent -autorelease too many times 

在過去的警告,我刪除了自動釋放,它走了,但我不知道如何釋放它,因爲它return語句中使用。

- (Client*) createNewClient { 
... 
    Client *client = [NSEntityDescription insertNewObjectForEntityForName:@"Client"inManagedObjectContext:dataInterface.managedObjectContext];   
... 
    return client; 
} 

一般情況下,我該怎麼處理這些問題?

+1

其中Xcode版本? – 2011-04-29 06:13:21

+0

@Bavarious XCode版本4 – Jim 2011-04-30 00:49:41

回答

0

由於您不擁有由insertNewObjectForEntityForName:返回的對象,因此您不必釋放它。

Apple Memory Management Programming Guide

你把一個對象的所有權,如果你 使用其名稱 開始「黃金」,「新」,「複製」的方法創建它,或 「mutableCopy」 (例如,alloc, newObject或mutableCopy),或者如果您向其發送保留消息 。

insertNewObjectForEntityForName:包含'新',但不以它開頭。

0

這可能是一個標記爲命名約定。如果要返回自動釋放對象,請嘗試將其重命名爲:

- (Client *)clientWithCurrentContext