开发者

Memory Leak in Foundation NSCFString. NSString created and Released. Still Leaks

I am getting a leaked NSCFString from this code. I understand it has to do with the NSString however, I do not understand how the leak is happening. Thanks f开发者_运维问答or your help in advance...

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{

    NSString *pTitle = [[NSString alloc] initWithString:placemark.title];

    mapView.userLocation.title = pTitle;
    [pTitle release];


}


Are you also leaking a map view? In that case the reported leak of this string is just by extension of the leaked map view.

Most often the most leaked object is not the culprit. The culprit is usually a single object holding on to a dozen of the most leaked object.

Also, you can cut down your code to:

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
    mapView.userLocaltion.title = placemark.title;
}

No need doing memory management when not needed :).


There are alot of bugs in Apple's Framework buddy.. don't worry about the leaks from framework.

Just follow the rules at your side. For every alloc, copy or retain, there must be a corresponding release.

Also iOS handles NSString in a quite different way..So it is better to stick with the rules.

hope it helps..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜