I am trying to empty an NSMutableArray with the [myarray removeallobjects]; but I am getting error exc_bad_access. Is this the right way to empty the array? I tried to set it to nil but its not working either. Actually what I am doing is filling the array with data and the user has the option to "refresh" the data and I want to empty the array before enter the refreshed data. I cant post any code because is too big.
-[NSMutableArray removeAllObjects]
is the correct way of emptying an NSMutableArray
. You're most likely getting a crash because you're still using the objects that you removed somewhere, in your UI perhaps.
I think the problem is in this snippet of code that you've provided in the comments,
[checkinArray addObject:checkinsA];
[checkinsA.taggedID release];
[checkinsA.taggedName release];
[checkinsA release];
taggedID
and taggedName
are properties of the checkinsA
object. They should be released in the dealloc
method only. The array does not retain the object tree. It retains the root object only. So there shouldn't be a release here. So knock out the two lines in the middle and make it
[checkinArray addObject:checkinsA];
[checkinsA release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With