views:

65

answers:

1

I ran Instruments on my iPad app to check for leaks. It found several "leaks" where an object was being retained in a method:

alt text

But these objects are released later in dealloc:

alt text

Are these classified as false-positives?

+1  A: 

Is self.detailPopover a property declared with retain? If so then the assignment self.detailPopover will result in the generated set method calling retain on the object returned from alloc that you already own.

If it is a retained property then remove self from the assignment so the set method is not called and your retain count will be correct.

Property* prop = [[Property alloc] init]; // retain count == 1 
self.property = prop; // retain count == 2 
[prop release]; // retain count == 1 

or avoid the generated set method and it's retain...

property = [[Property alloc] init]; // retain count == 1 
Gary
I'm a bit confused. I was under the impression that you were supposed to use self whenever you assign an object to a property, to make sure it goes through the appropriate setter.
macatomy
In general yes, however you need to be careful in the class implementation. Any object returned from alloc is already owned by you so you can either call release after assigning the object or assign directly to the member variable.
Gary
Thanks, that makes sense now.
macatomy