Performing Static Analysis Using Both Xcode 3.2 and Nikita Zhuk Analysis Tool I often came across this couple of warnings:
The method returns an Objective-C object with a retention value of +0 (link without owner)
An incorrect decrement of object reference counting does not currently belong to the caller
Example code that might trigger this warning:
UIButton* button = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame: CGRectMake(x, y, width, height)];
return button;
I assumed that the buttons created in this way are auto-implemented, like any other NSObject created using the convenient factory method. Therefore, I return it, and the caller can decide whether to save it or not. What is the problem with this?
Do I have to save and auto-update the object before returning it? And most importantly, can this warning warn what will ever be the cause of terrible release related crashes?
Now I understand that this only happens with UIButtons. Is this because it is a class cluster?
EDIT: The snapshot below shows the minimal time that clang issues these warnings (with warnings in bold). Both warnings are marked in the statement creating the object (message buttonWithType:).
-(UIButton*) ztupidTezt:(UIImage*) img
{
UIButton* bt = [[UIButton buttonWithType:UIButtonTypeCustom]initWithFrame:
1 The method returns an Objective-C object with a +0 save counter (link without owner)
2 An incorrect decrement of object reference counting does not currently belong to the caller
CGRectMake(0.0f, 0.0f, img.size.width, img.size.height)];
bt setImage:img forState:UIControlStateNormal];
return bt;
}