일부 이미지를로드하는 UIScrollView가 있습니다. 가끔 이미지에 효과를 적용하는 데 약간의 시간이 걸리므로 사전로드가 필요하므로 detachNewThreadSelector를 사용하여 다른 스레드에서이 작업을 수행하기로 결정했습니다. . 나는 이것을 위해 gitHub에있는 KTPhotoBrowser를 사용하고있다.iOS detachNewThreadSelector leaking
그래서 기본적으로 나는 기능을 가지고 있습니다.
- (void)setCurrentIndex:(NSNumber *)newIndex
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
currentIndex_ = [newIndex integerValue];
[self loadPhoto:currentIndex_];
[self loadPhoto:currentIndex_ + 1];
[self loadPhoto:currentIndex_ - 1];
[self unloadPhoto:currentIndex_ + 2];
[self unloadPhoto:currentIndex_ - 2];
[self setTitleWithCurrentPhotoIndex];
[self toggleNavButtons];
[pool release];
}
나는 내가 이것을 실행하면이
[NSThread detachNewThreadSelector:@selector(setCurrentIndex:) toTarget:self withObject:[NSNumber numberWithInt:5]];
를 사용하여, 그것은 누출을 던지는 것으로 보인다 호출합니다. loadPhoto 메서드의 코드 주위에 AutoRelease 풀을 넣어야하는지 궁금해지기 시작했습니다. 이 코드에 대해 궁금하신 분은 아래에 포함 시켰습니다.
- (void)loadPhoto:(NSInteger)index
{
if (index < 0 || index >= photoCount_) {
return;
}
id currentPhotoView = [photoViews_ objectAtIndex:index];
if (NO == [currentPhotoView isKindOfClass:[KTPhotoView class]]) {
// Load the photo view.
CGRect frame = [self frameForPageAtIndex:index];
KTPhotoView *photoView = [[KTPhotoView alloc] initWithFrame:frame];
[photoView setScroller:self];
[photoView setIndex:index];
[photoView setBackgroundColor:[UIColor clearColor]];
// Set the photo image.
if (dataSource_) {
if ([dataSource_ respondsToSelector:@selector(imageAtIndex:photoView:)] == NO) {
UIImage *image = [dataSource_ imageAtIndex:index];
[photoView setImage:image];
} else {
[dataSource_ imageAtIndex:index photoView:photoView];
}
}
[scrollView_ addSubview:photoView];
[photoViews_ replaceObjectAtIndex:index withObject:photoView];
[photoView release];
} else {
// Turn off zooming.
[currentPhotoView turnOffZoom];
}
}
모든 아이디어는 크게 감사하겠습니다.
누출되는 개체의 종류를 정확하게 알려줄 수 있습니까? –
나는 곧 무슨 일이 일어나는지 보려고기구를 통해 달릴 것입니다. 결과를 다시보고하겠습니다. – jabroni