没有详细信息/行号的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

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

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

我一般怎么处理这些呢?

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

来自Apple内存管理编程指南:

你拥有一个对象,如果你使用一个方法来创建它以" alloc ", " new ", " copy "或开头mutableCopy(例如,alloc,newObject,或者mutableCopy),或者如果你给它发一个保留消息

insertNewObjectForEntityForName:包含'New',但不以它开头。

这可能是命名约定的标记。如果你想返回一个自动释放的对象,试着将它重命名为:

- (Client *)clientWithCurrentContext

最新更新