sicKo
sicKo

Reputation: 1256

NSMutablearray removeallobjects crash my app. Works fine in 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.

Upvotes: 2

Views: 2913

Answers (2)

Perception
Perception

Reputation: 80623

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.

Upvotes: 4

tjg184
tjg184

Reputation: 4686

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

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

Upvotes: 1

Related Questions