放宽这里吗? [英] Overreleasing here?

查看:66
本文介绍了放宽这里吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序的特定Beta版中,我已经在某些设备上获得EXC_BAD_ACCESS,请参见此处: 帮助调试iPhone应用-EXC_BAD_ACCESS

I have been getting EXC_BAD_ACCESS on some devices in ad hoc beta for my app see here: Help debugging iPhone app - EXC_BAD_ACCESS

我设法使用了atos -arch armv6 -o myapp.app/myapp 0x000037a6 在终端中查找导致此问题的方法,这将我引向了这段代码:

I have managed to use atos -arch armv6 -o myapp.app/myapp 0x000037a6 in terminal to track down the method that's causing this problem, and it's lead me to this piece of code:

for (UIView *view in scrollView.subviews) {
    [view removeFromSuperview];
}

我怀疑该应用程序正在收到内存访问警告,并释放其子级的scrollview或UIImageViews,因此当我在上面使用该方法时,由于它过度释放了视图,因此它会遇到错误(并崩溃).

I suspect that the app is receiving a memory access warning, and releasing the scrollview or UIImageViews which are it's children, so when I use that method above, it hits an error (and a crash), since it's overreleasing a view.

我的问题是,如何使它安全,以便仅在尚未发布时才发布?

My question is, how can I make this safe, so that it's only released if it hasn't yet been released?

推荐答案

在迭代数组时,您正在修改数组.它很微妙,但是由于removeFromSuperview从子视图列表中将其删除,因此您正在更改数组.将您的代码更改为此,

You are modifying an array while you iterate over it. It's subtle, but because removeFromSuperview removes it from the list of subviews, you are changing the array. Change your code to this,

NSArray *subviews = [scrollView.subviews copy];
for (UIView *view in subviews) {
    [view removeFromSuperview];
}
[subviews release];

你应该没事.

这篇关于放宽这里吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆