2011-04-29 44 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