1

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 the 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.

2
  • Are you debugging in debug configuration? Optimizations can make the flow of your code jumpy. Commented Feb 12, 2011 at 19:29
  • yes. I'm debugging with debug profile. The code is really called twice, because I raise an error when I try to find "s" and it does not exists. Commented Feb 12, 2011 at 19:45

2 Answers 2

2

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it was non-nil, contained only the removed instance
1

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...

2 Comments

Gotta love those. Think of how much you've grown as an iOS programmer by tracking that down. ;)
Exact. I miss the time when understanding UITableView was my biggest problem. :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.