아래 표시된 줄이 예외를 던지는 이유에 대한 단서가 있습니까?배열 검사의 예외 경계가 잘못입니까?
-(double)calibrationValueAtIndex:(int)index
{
NSLog(@"count: %d index: %d",[theTopValues count], index);
return [[theTopValues objectAtIndex:index] doubleValue]; // exception happening here
}
2012-07-23 21:51:16.448 TestAppTimerAndHits[15130:f803] count: 9 index: 7
2012-07-23 21:51:22.339 TestAppTimerAndHits[15130:f803] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSOrderedSetM objectAtIndex:]: index 7 beyond bounds [0 .. 4]'
어떻게 경계가 [0 .. 4]
을 것을, 다음 예외가보고 전에 라인 (9)의 수를 NSLog 수 있습니까?
예외가 '무작위로'던져진 것처럼 보입니다. 배열 경계가 괜찮아서 색인 8에서 개체를 가져올 수 있다는 것을 의미하지만 ... 다른 시간에 범위가 [0 .. 2]
으로보고됩니까? 뷰 컨트롤러 (프로젝트 단지 하나 VC)
theBufferManager = [HitBufferManager의 ALLOC] INIT]에서
;
in .h 파일 : @property NSMutableOrderedSet * theTopValues;
(.m 파일) : @TopValues를 합성합니다.
- (id) HitBufferManager의 경우 : theTopValues = [NSMutableOrderedSet orderedSetWithCapacity : numToStore]; // 자동 완성 된 버전을 반환합니다.
개별 항목
편집/추가됩니다 [self sortTopValues];
if([theTopValues count]<numToStore)
{
[theTopValues addObject:[NSNumber numberWithDouble:windowVal]];
}
else if(logVal> [[theTopValues objectAtIndex:0] doubleValue])
{
[theTopValues replaceObjectAtIndex:0 withObject:[NSNumber numberWithDouble:logVal]];
}
이것은 멀티 스레드 프로그램의 일부분이 아닙니다. – dasblinkenlight
그게 궁금 해서요 ... 그리고 내가 메모리 관리에 문제가 있는지 궁금해하고 있습니다. 어떤 이유로 배열의 요소가 가비지 수집되는 것 같아요? 그것은 아이폰 OS/아이폰 애플 리케이션이며, 나는 멀티 스레드로 만들 의도적 인 일은하지 않았지만, 그것은 나의 첫 번째 응용 프로그램이다. 그래서 어쨌든 멀티 스레드를 시도한다는 것을 알지 못할 수도있다. – DoYouLikeHam
iOS 용인 경우 GC가 없으며 참조 횟수 만 있습니다. 하지만 매달린 참조가있을 수 있습니다. ARC를 사용합니까? – dasblinkenlight