iPhone 앱 개발에 XCode를 사용하고 있습니다. 이 플랫폼을 처음 사용하고 특정 문제에 대한 도움이 필요합니다 ...NSMutableArray로 인해 충돌이 발생합니다.
데이터를 처리하고 NSMutableArray로 래핑 된 NSNumber로 두 정수 값을 반환하는 메서드가 있습니다.
-(NSMutableArray *)processPoints:(int) x:(int) y
{
NSMutableArray *mutArray = [[NSMutableArray alloc] initWithCapacity:3];
int x9,y9;
// ...do some processing...
NSNumber* xNum = [NSNumber numberWithInt:x9];
NSNumber* yNum = [NSNumber numberWithInt:y9];
[mutArray addObject:xNum];
[mutArray addObject:yNum];
return [mutArray autorelease];
}
난 로컬 변수로의 NSNumber 물건을 복사하고 NSMutable 어레이의 로컬 복사를 방출하는 다른 방법에서 상기 메소드를 호출 여기
는 방법이다.하지만이 NSMutable 배열 (변수 'mutArray')을 공개하면 앱이 다운됩니다. I 메모리 해제의 과정을 잘못 하겠어 어디
-(void)doNinjaAction
{
NSMutableArray* mutArray = [self processPoints: x :y];
NSNumber* s1 = [[mutArray objectAtIndex:0] retain];
NSNumber* s2 = [[mutArray objectAtIndex:1] retain];
x = [s1 integerValue];
y = [s2 integerValue];
//...proceed with other stuff...
[mutArray autorelease]; //this is where the system crashes. same for 'release'
//instead of 'autorelease'
}
당신이 설명해 주시겠습니까 : 여기
는 방법이다.내 프로세스에 대한 이해는 약간 불안정합니다. 도와주세요. 당신이 문을
NSMutableArray* mutArray = [self processPoints: x :y];
를 호출 할 때
두 번 자동으로 해제하기 때문에 충돌합니다. –