0

我运行了分析器,发现了一些我无法与代码中的行关联的警告。我不确定如何处理它们。单击它们会将我带到编辑器中的正确文件,但分析器摘要结果告诉我很多。我不知道这些中的每一个都指的是什么,并且逐行浏览代码并不高效(我不知道我在寻找什么)。

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

对于最后一个警告,我删除了自动释放,它消失了,但我不知道如何释放它,因为它在返回语句中使用。

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

一般来说,我该怎么处理这些?

4

2 回答 2

0

由于您不拥有由 返回的对象,因此insertNewObjectForEntityForName:您不必释放它。

Apple 内存管理编程指南

如果您使用名称以“alloc”、“new”、“copy”或“mutableCopy”开头的方法(例如,alloc、newObject 或 mutableCopy)创建对象,或者如果您发送对象,则您将获得对象的所有权保留消息。

insertNewObjectForEntityForName:包含“新”,但不以它开头。

于 2011-04-29T11:13:21.223 回答
0

这可能是命名约定的标志。如果要返回自动释放的对象,请尝试将其重命名为:

- (Client *)clientWithCurrentContext
于 2011-04-29T15:07:44.780 回答