开发者

Got warning "Incorrect decrement of the reference count of an object that is not owned at this point by the caller"

开发者 https://www.devze.com 2023-04-12 17:41 出处:网络
When \'Analyse\', Got warning \"Incorrect decrement of the reference count of an object that is not owned at this point by the caller\" in this. (xCode 4.1+)

When 'Analyse', Got warning "Incorrect decrement of the reference count of an object that is not owned at this point by the caller" in this. (xCode 4.1+)

I can understant that it's better to "kill" an object from it's proper class, but is there a way to do it from outside without a warning?

Thanks!

NSLog(@"--[%s:%d]",__PRETTY_FUNCTION__, __LINE__);
myAppDelegate* appDelegate = [[UIAppl开发者_运维技巧ication sharedApplication] delegate];
   if (appDelegate.referencesPopup != nil) {
        [appDelegate.referencesPopup release]; // warning
        appDelegate.referencesPopup = nil;  
   }      
}


Just set the property to nil, there is no need to release it here, as the analyzer is telling you. If you didn't retain it, don't release it.

Also, you shouldn't call release on something that is returned by a dot notation getter. This has been discussed extensively here: Why shouldn't I use the getter to release a property in objective-c?


Most likely, the way in which you are acquiring the object being stored in referencesPopup, you did not allocate it yourself or retain it. In that case, you are not responsible for releasing it. You can simply set the ivar to nil.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号