At some point I allocate a NSMutableData element like this:
NSMutableData* data=[[NSMutableData alloc] initWithLength:0];
Later, I do:
NSString *dataAsStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ;
completeCommand = [NSString stringWithFormat:@"%@%@",
incompleteMessage,
[dataAsStr substringWithRange:NSMakeRange(startIndex, i-startIndex)]];
[incompleteMessage release];
incompleteMessage = nil;
[dataAsStr release];
And finally I call:
[data release]; //Here I get a BAD_ACCESS error since data gets a release count of -1
Now according to instruments (Allocations with zombie support), the first line of the second block NSString *dataAsString = ... calls [data release]
Where does that happen?
The mistery is solved.. Its a rather big method, so I didn't realize that [data release]; was in a loop and its alloc was not. That was causing the zombie.