开发者

NSMutablearray removeallobjects crash my app. Works fine in NSZombie

开发者 https://www.devze.com 2023-03-16 08:45 出处:网络
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 po

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开发者_StackOverflow社区 to run it using NSZombie thingy. But it won't crash at all.


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.


I believe you might be retaining your object an extra time.

self.otherDealsList = [[[NSMutableArray alloc] init] autorelease];
0

精彩评论

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