MKReverseGeocoder and memory management?

I would like to ask about memory management regarding MKReverseGeocoder , prior to iOS4.3. I used the code below by highlighting MKReverseGeocoder and then releasing it in both reverseGeocoder:didFindPlavemark and reverseGeoCoder:didFailWithError ,

However, with iOS4.3, I get EXC_BAD_ACCESS and it seems to come from a release in reverseGeoCoder:didFailWithError . I would really appreciate it if someone could point me in the right direction, can I use autoRelease, will this mean that geoCoder will be long enough for the delegate to do his job?

 // ALLOC & START MKReverseGeocoder *myGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:[lastGoodLocation coordinate]]; [myGeocoder setDelegate:self]; [myGeocoder start]; 

.

 // DID FIND - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { NSLog(@"GEOCODE: didFindPlacemark"); [self createLocation:placemark]; [geocoder release]; } 

.

 // DID FAIL - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { NSLog(@"GEOCODE: didFailWithError"); [self createLocation:nil]; [geocoder release]; } 
+4
source share
1 answer

After a little searching, I think the solution could be to install iVar to store MKReverseGeocoder. That way I can use autorelease, but I'm still sure that iVar will be held on geoCoder until the next moment iVar is installed. Interestingly, the above code only creates EXC_BAD_ACCESS from reverseGeocoder:didFailWithError , and not from reverseGeocoder:didFindPlacemark . I also checked the number of deductions (yes, I know that it is not reliable, but I wanted to see), and before the release (which crashes) both methods report saving the quantity 1. The only thing I can guess is that geocoded the object can still be somewhere when I do the release. It also feels the messy distribution in one method and the release with a pointer from the callback.

 @property(nonatomic, retain)MKReverseGeocoder geoCoder; 

.

 [self setGeoCoder:[[[MKReverseGeocoder alloc] initWithCoordinate:coord] autorelease]]; [[self geoCoder] setDelegate:self]; [[self geoCoder] start]; 
+3
source

Source: https://habr.com/ru/post/1343633/


All Articles