Xcode 工具 - 修复泄漏
在 xcode 仪器中测试我的 IOS 应用程序时,我遇到了几次内存泄漏。谁能明白为什么标有“-->”的行正在泄漏?
--> CLLocationCoordinate2D newCoord = CLLocationCoordinate2DMake(latitude, longitude);
--> MapAnnotation* annotation = [[MapAnnotation alloc] initWithCoordinate:newCoord];
[mapView addAnnotation:annotation];
[annotation release];
另外,我似乎也有一些泄漏的结构;
--> double placeLat = [place.latitude doubleValue];
没有指向“placeLat”变量的指针,所以我无法释放它? :
谢谢克里斯蒂
/
I have several memory leaks when testing my IOS application in xcode instruments. Can anyone see why the lines marked with "-->" are leaking?
--> CLLocationCoordinate2D newCoord = CLLocationCoordinate2DMake(latitude, longitude);
--> MapAnnotation* annotation = [[MapAnnotation alloc] initWithCoordinate:newCoord];
[mapView addAnnotation:annotation];
[annotation release];
also, I seem to have some structs which are leaking too;
--> double placeLat = [place.latitude doubleValue];
there is no pointer to the "placeLat" variable, so I can't release it? : /
thanks
Christy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所展示的那样,您的代码是正确的。
您必须记住的一件事是,Leaks 会向您显示创建泄漏对象的位置,而不是您做错事而导致泄漏的位置。
这是一个重要的区别。事实上,在第一种情况下,很可能正是注释对象在代码中的其他地方泄漏了。您应该检查 Instruments 以堆栈跟踪形式显示的所有执行流程。
Your code is correct, as much as you show of it.
One thing you have to keep in mind is that Leaks will show you the place where the leaked object is created, not the place where you do something wrong that will produce the leak.
This is an important difference. Indeed, it could well be, in the first case, that is the very
annotation
object which is leaked somewhere else in your code. You should check all the flow of execution that Instruments is showing you as stack trace.