-1

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

Joris Weimar
  • 3,966
  • 3
  • 29
  • 48
  • What are you doing with `k` after this point? – Richard J. Ross III Nov 15 '12 at 16:25
  • @chrislhardin what? That's most definitely not the case. `NSMutableArray` is (usually) implemented with a linked-list in the backing, and `NSArray` uses an actual array. Different circumstances and constructors though, can change how it's backed. – Richard J. Ross III Nov 15 '12 at 16:27
  • 2
    What's happening is something outside of those two lines. I copied them into an old (pre-ARC) test project and got no errors. – Phillip Mills Nov 15 '12 at 16:30
  • have you done a clean on the project? cmd-shift-k – Sam Clewlow Nov 15 '12 at 16:44
  • also have you done a `po ` in the debugger to check its the same array? – Sam Clewlow Nov 15 '12 at 16:48
  • i did a clean on the project. it doesn't really matter what happens outside those line because when i step through the project the error happens right on the release – Joris Weimar Nov 15 '12 at 19:30
  • 1
    @JorisWeimar: It does matter. After you release it, you cannot use the NSMutableArray object pointed to by `k` again -- the object is deallocated and `k` becomes a dangling pointer. You could use the *variable* `k` again, but before you do that you must assign `k` to point to another object or `nil`. – newacct Nov 15 '12 at 19:42
  • in my case it doesn't matter because as i said, i'm stepping through the debugger line by line. the message is generated as i step over the [k release]; line. i do nothing else with k afterwards either, but even if i did, that shouldn't cause the message on the release message. – Joris Weimar Nov 15 '12 at 19:45
  • @JorisWeimar: okay, so if it "doesn't matter", then you can remove all the rest of the code and it will still crash, right? – newacct Nov 15 '12 at 21:46
  • so lame to down vote without comment.... i mean.. obviously something is causing it. i'll strip my app more and more until nothing is left except those two lines. otherwise it might be a debugger bug – Joris Weimar Nov 16 '12 at 12:55
  • The downvote is likely because the code, as shown, cannot possibly be the source of the problem. There *must* be additional details in play . – bbum Nov 16 '12 at 17:06

2 Answers2

1

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.

Community
  • 1
  • 1
Snaker
  • 695
  • 7
  • 20
  • yeah, i checked the ARC. that's what i first thought. also, it's giving me that error exactly on the release line when i step through it with the debugger. i was just using retainCount to see what the count is. it should be 1 at that point, and it is. – Joris Weimar Nov 15 '12 at 19:29
  • 1
    If he were using ARC, `release` would be forbidden. So that cannot be the case. – newacct Nov 15 '12 at 19:37
0

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];
}
Chris Walken
  • 254
  • 1
  • 7