비슷한 문제를 검색하려고했지만 좋은 해결책을 찾지 못했습니다. 누군가가 나를 도울 수 있기를 바랍니다. 기본적으로메모리 누수, nsmutablearray 및 사용자 지정 개체
나는 카드 객체와 배열합니다 (tempArray가 생성되고이 루프 위에 채워집니다) 웁니다이 방법에서 누출이 있습니다
for(int i = 0; i < numberOfCards; i += 2) {
int randomNumber = (arc4random() % [tempArray count]);
NSNumber *number = [tempArray objectAtIndex:randomNumber];
[tempArray removeObject:number];
Card *card1 = [[Card alloc] initWithCategory:category andNumber:[number intValue]];
Card *card2 = [[Card alloc] initWithCategory:category andNumber:[number intValue]];
[number release];
[cards addObject:card1];
[cards addObject:card2];
}
이 방법은 좀 더 논리를 포함 않습니다,하지만 나는 꽤이 루프가 누수가 포함되어 있는지 확인하십시오. 인스 트루먼 트와 함께 실행할 때, 카드 오브젝트가 해제되지 않습니다. dealloc 메서드에서 배열을 해제했는데 배열 안에있는 객체도 해제 할 것이라고 생각했습니다.
-(void) dealloc {
[cards release];
[super dealloc];
}
나는 card1과 card2에서 autorelease를 시도하여 클래스 변수로 만들려고 시도했다. 그러나 아무것도 도움이되는 것 같지 않습니다. 누수가 있거나 카드 1 또는 카드 2에 릴리스를 추가하려고하면 응용 프로그램이 충돌합니다. 누구나 여기서 무엇이 잘못 됐는지 알 수 있습니까?
N.B. 후 당신이 소유하지 않기 때문에'number'를 공개해서는 안됩니다. – albertamg
팁, 감사합니다. –
당신은 환영합니다 :) – albertamg