NSMutablearray removeallobjects 使我的应用程序崩溃。在 NSZombie 中运行良好
这就是我声明 NSMutablearray 的方式,
self.otherDealsList = [[NSMutableArray alloc] init];
我将从 Web 服务中获取一些值并将其插入到该数组中。这个可变数组用于填充我的表格视图数据。但是当用户单击按钮时,我想从 Web 服务获取新数据并将其插入到可变数组中。
在替换可变数组内容的过程中,如果用户单击或滚动 tableview,应用程序将崩溃。因此,为了避免这种情况,我尝试首先通过清空可变数组并重新加载表来清空表视图。这是我使数组为空的代码,
if ([self.otherDealsList count] > 0) {
[self.otherDealsList removeAllObjects];
[tableView reloadData];
}
但是当我的应用程序在 'removeallobjects'
行上运行时,它不断崩溃(“错误访问”
)。我很确定我没有在任何地方发布它。
我还尝试使用 NSZombie 来运行它。但它根本不会崩溃。
This is how i declare my NSMutablearray
self.otherDealsList = [[NSMutableArray alloc] init];
I'll get some values from a webservice and insert it into this array. This mutable array is used to populate my tableview data. But when user clicks a button, I want to get new data from the webservice and insert it back to the mutable array.
During the process of replacing the content of the mutable array, if the user clicks or scrolls the tableview, the app will crash. So to avoid this, I tried to empty the table view first by emptying the mutable array and reload the table. This is my code to make the array empty
if ([self.otherDealsList count] > 0) {
[self.otherDealsList removeAllObjects];
[tableView reloadData];
}
But my app keeps crashing ("Bad access"
) when it run on 'removeallobjects'
line. I'm pretty sure I didn't release it anywhere.
I also tried to run it using NSZombie thingy. But it won't crash at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我正在向您链接另一个与您的问题非常相似的问题。您很可能在调用removeAllObjects之前释放了NSMutableArray中的一些对象,这就是导致您的问题的原因。请在此处阅读更多信息 - NSMutableArray removeAllObjects 崩溃。
I am linking you another SO question very similar to yours. You are most likely releasing some objects in the NSMutableArray before calling removeAllObjects and that is what is causing your problem. Please read more here - NSMutableArray removeAllObjects crash.