Core Data produces Analyzer warnings
I am doing the final touch ups on an app and I am getting rid of every compiler/analyzer warning.
I have a bunch of Class methods that wrap my apps access to Core Data entities. This is "provoking" the analyzer.
+ (CDProductEntity*) newProductEntity {
return (CDProductEntity*)[NSEntityDescription insertNewObjectForEntityForName:@"CDProductEntity" inManagedObjectContext:[self context]];
}
Which results in an Analyzer warning:
Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected
In the method that calls the above Class Method I have this:
CDProductEntity *newEntity = [self newProductEntity];
Which results in an Analyzer warning:
Method returns an Objective-C object with a +1 retain count (owning reference)
Explicitly releasing or autoreleasing a Core Data entity is usually very very bad, but is that what it is asking me to do here? First it tells me it has a +0 retain count and that is bad, then it tells me it has a +1 which is also bad.
What can I do to ensure that I am either dealing with a Analyzer hiccup or that I release correctly?
Thanks in advance
The problem static analyzer complains about may be in your method name - per obj-c naming conventions methods with alloc, new or copy in their names are expected to return objects that caller 'owns' and must release - and your method returns autoreleased object.
quote from docs:
You own any object you create.
You “create” an object using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy).
So for a start try I'd suggest just removing 'new' from your method name
链接地址: http://www.djcxy.com/p/43732.html上一篇: 静态分析仪说我有泄漏....为什么?
下一篇: 核心数据会产生分析器警告