Strange bug in NSMutableArray removeObject
I have this snippet:
1: if ((s >= kEnumValue1) && (s <= kEnumValue2)) {
2: MyObject * o = [self findObjectFor:s];
3: if ([o isValidFor:self]) {
4: [arrayOfMyObjects removeObject:o];
5: for (MyObject * mo in arrayOfMyObjects) {
6: ...
7: }
8: }
9: }
For some really weird reason, when my code reaches line 4, if I step over, it goes back to the start of th开发者_如何学Ce method on the same thread, without going thru lines 5-. Does anybody have any clue why this happens?
removeObject on NSMutableArray does not mention any exception.
It is safe to assume that you did not find a bug in removeObject:
(unless you wrote your own).
Have you checked arrayOfMyObjects
? Is it non-nil? Does it contain anything?
OK, after lots of debugging in all classes on my project, I found that, when MyObject's release is called, it calls "release" on another class (since it is the last reference, it calls "dealloc"), once again for a third class, and then, it invokes removeObjectForKey:nil in NSMutableDictionary. This raises an NSInvalidArgumentException that is not logged at all. Way too evil...
精彩评论