문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top