Question

In didFinishLaunchingWithOptions, the first code is:

NSMutableArray *k = [[NSMutableArray alloc] initWithCapacity:10];
[k release];

(I reduced it to this case after much debugging) and I'm getting

*** -[__NSArrayM class]: message sent to deallocated instance 0x7576c90
*** -[__NSArrayM respondsToSelector:]: message sent to deallocated instance 0x7576c90

If I check the retainCount on 'k' after the alloc line, it is 1. If I replace NSMutableArray by NSArray everything is fine. What the heck is going on here??

Was it helpful?

Solution

That error must be coming from somewhere else. Which means you're using it. Else, you wouldn't have

*** -[__NSArrayM respondsToSelector:]: message sent to deallocated instance 0x7576c90

But something like :

*** -[__NSArrayM release]: message sent to deallocated instance 0x7576c90

Plus, you should not use retainCount (see why here).

Just check that you're not using it anywhere else. Or maybe you're using ARC ? In which case you don't need to release it.

OTHER TIPS

If you have zombies enabled and are still seeing an error in the console like:

2013-08-26 16:08:22.540 test[1231:303] * -[__NSDictionaryM respondsToSelector:]: message sent to deallocated instance 0x101b039a0

And you have distilled your code down to just a few lines and you are sure you are not over releasing the object, the problem is most likely caused by the debugger sending messages to the already correctly released object when you are single stepping past it. The console messages are not emitted when you do not step through the code. To see it happen, enable zombies and single step through the code below. After the release the above message is sent to the console.

-(void)testDictionary
{
  NSMutableDictionary *outboundDictionary = [[NSMutableDictionary alloc] init];
  [outboundDictionary release];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top