Franck
Franck

Reputation: 9329

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

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 = [[UIApplication sharedApplication] delegate];
   if (appDelegate.referencesPopup != nil) {
        [appDelegate.referencesPopup release]; // warning
        appDelegate.referencesPopup = nil;  
   }      
}

Upvotes: 0

Views: 500

Answers (2)

Mark Granoff
Mark Granoff

Reputation: 16938

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.

Upvotes: 0

jrturton
jrturton

Reputation: 119242

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?

Upvotes: 2

Related Questions