dealloc of instance variables in custom method

AppCode tells me if my synthesized properties are not released in a dealloc method - very nice feature.

However, in our project, we have decided to move the release of properties to a helper method called "resetProperties". The method is called from dealloc and from viewDidUnload.

It would be very nice if we could configure AppCode to look for property releases in a custom method instead of only in dealloc.

3 comments
Comment actions Permalink

Actually it does. AppCode considers an ivar as released if a 'release' or 'autorelease' message was sent to it in ANY method of the class, or if nil was assigned to its property in 'dealloc' method of the class, or it was used somehow in the 'dealloc' method. This is pretty conservative condition. Please send us any example where AppCode shows the warning when the ivar was actually released.

0
Comment actions Permalink

I see that you are right.

If I put a

[searchBar release];

inside my resetProperties, the warning disappears promptly.

I guess I should also have told you that the property I am releasing looks like this in the .h file:

@property (nonatomic, retain) IBOutlet UISearchBar *searchBar;

and in our resetProperties we "release" it like this:

self.searchBar = nil;

So the property is released implicitly and we do not have the risk of having an object pointing nowhere. We feel that this is a more robust approach.

We aim to have most properties with "retain", and release them implicitly like this. It makes our code more uniform.

0

Please sign in to leave a comment.