Foundation NSCFString 中的内存泄漏。 NSString 创建并发布。仍然泄漏
我从这段代码中得到了一个泄露的 NSCFString 。我知道它与 NSString 有关,但是我不明白泄漏是如何发生的。感谢您提前的帮助...
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
NSString *pTitle = [[NSString alloc] initWithString:placemark.title];
mapView.userLocation.title = pTitle;
[pTitle release];
}
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 for your help in advance...
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
NSString *pTitle = [[NSString alloc] initWithString:placemark.title];
mapView.userLocation.title = pTitle;
[pTitle release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你还泄露了地图视图吗?在这种情况下,报告的该字符串的泄漏只是泄漏的地图视图的扩展。
大多数情况下,泄露最多的对象并不是罪魁祸首。罪魁祸首通常是一个单一的对象,它持有十几个最容易泄露的对象。
另外,您可以将代码缩减为:
不需要时无需进行内存管理:)。
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:
No need doing memory management when not needed :).
苹果的框架有很多错误,兄弟。不用担心框架的泄漏。
只需遵守您身边的规则即可。对于每个
alloc
、copy
或retain
,都必须有一个相应的release
。此外,iOS 以完全不同的方式处理
NSString
。所以最好遵守规则。希望它有帮助..
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
orretain
, there must be a correspondingrelease
.Also iOS handles
NSString
in a quite different way..So it is better to stick with the rules.hope it helps..