ios - MKReverseGeocoder autorelease/release question in Apple's CurrentAddress sample -


i looking @ code lifted straight mapviewcontroller.m file in currentaddress sample available on apple's web site:

- (void)dealloc {     [reversegeocoder release];     [mapview release];     [getaddressbutton release];      [super dealloc]; }  - (ibaction)reversegeocodecurrentlocation {     self.reversegeocoder =         [[[mkreversegeocoder alloc] initwithcoordinate:mapview.userlocation.location.coordinate] autorelease];     reversegeocoder.delegate = self;     [reversegeocoder start]; } 

i wondering function of autorelease when allocating object. (the reversegeocoder ivar in mapviewcontroller class set retain property.) have code similar in application, , seems work either way.

setting reversegeocoder property increments retain count (+1), since you're creating object alloc+init (+1), need autorelease (-1) not end 2 retain count.

it work either way, difference when not autorelease, leak.

the reversegeocoder ivar

it sure is, note when you're using self.reversegeocoder form, you're not accessing ivar directly - instead, you're calling relevant setreversegeocoder: function, either written or @synthesized compiler.

see: http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/memorymgmt/memorymgmt.html

and: what equivalent code synthesized declared property?


Comments