Objective C: [MyObject alloc] now crashes under iOS SDK 4.1?

This is not really an answer but some ideas to move forward.

This is not really an answer but some ideas to move forward. The only causes that leap to mind at the moment are memory corruption and some sort of link issue. Perhaps you are linking two versions of the class somehow.

Assuming this is the class, there doesn't look to be anything wrong to make it crash in alloc. There's no +initialize or anything. Questions I would be asking myself and trying to answer are: what happens if I rename the class?

What happens if I create a new identical class with a different name? The pointer that gets passed to obj_msgSend: is it reasonable? Does it point to something that looks like a class?

Do you ever subclass the class and do you use initialize on the subclass? Is the pointer always the same? If so you can watch what it points to and see if it changes during execution.

What happens if you send self to the class?

OK, finally found this. As Jeremy suggested, this turned out to be a regular memory stomper. The difficulty I had finding it was that it wasn't the Class object itself that was getting stomped, but the class' metaclass structure - which is a normal Class object but one level up, referenced by the class 'isa' pointer.

That's why the class looked OK to me when I inspected it in the debugger - I need to follow the isa pointer and dump memory at one level up to find this. Luckily for me, the class was only a subclass of NSObject - had it been deeply subclassed, this could have been much harder to find. I got my first clue after biting the bullet, reverse-engineering objc_msgSend, working out exactly what was on the stack frame, and following all the pointers.

Yep, the hard way :) Matt Gallaghar's post (and various others I found by following links) were invaluable in helping me through this maze - thanks guys! Burned a lot of time on this one, but on the up side I learned a hell of a lot about Objective C internals during the past day and a half :).

That seems nearly impossible. – Kendall Helmstetter Gelner Nov 20 at 23:12.

Thanks for these suggestions JeremyP - it is always good to have fresh suggestions after you've been banging your head against the keyboard all day! Your suggestion of creating an identical class with the same name appears to have fixed the problem. I have no idea why and I feel I need to understand what's going on here.

You're right it sounds like some kind of linker issue, but I still have no idea what could cause such a serious runtime error and not even produce a warning at build time. Re. The pointer, it does look reasonable, but something inside the class eventually gets dereferenced as a null pointer inside objc_msgSend.

Occasionally, after I have changed the code and rebuilt, I get a null pointer instead. This behaviour obviously suggests something nondeterministic like a memory stomp. I'll post my findings.

This shouldn't have been posted as another answer. This is simply a comment (albeit a lengthy one) on JeremyP's post. Remember that this is a Q&A site and not a Forum.

– Justin Niessner Sep 16 '10 at 19:58 Yeah, I deliberated over that, but it kind of is an answer (because one of the suggestions fixed the problem), and also writing a long comment like that with no newlines is pretty unreadable. – Echelon Sep 16 '10 at 21:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions