I received a crash from one of my app which appears weird with following logs:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM removeObjectAtIndex:]: index 4294967293 beyond bounds [0 .. 4294967293]'
As per stack trace this is coming from below piece of code:
if ([self.itemList count] > 0) {
[self.itemList removeAllObjects];
}
Per my understanding, removeAllObjects
is always a safe operation and should not end up in a crash like this. Am I missing something over here. Any guidance to right direction would be really helpful.
EDIT :
Here is my itemList
property declared:
@property (nonatomic, strong) NSMutableArray *itemList;
It is most likely caused by the property being non-atomic. As you mentioned this code is multi-threaded and you are using a property which is not thread safe.
- Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM removeObjectAtIndex:]: index 4294967293 beyond bounds [0 .. 4294967293]'
This error simply means that the object that has to be deleted is already deleted and hence the returned index is '4294967293.' Try to set the array to atomic. Also try using @synchronized as mentioned in a similar question here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.