보존주기에서 오는 것처럼 보이는 메모리 누수가 있습니다. 메모리 할당 크기가 때마다 증가하고이 코드를 실행 : 나는 메모리 남용 이벤트를 얻을 때까지 경계없이자기없이 사이클을 유지합니까?
self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(nextPhoto) userInfo:nil repeats:YES];
총 메모리 사용 증가 : 코드는 2 초 타이머에 루핑
- (void)nextPhoto {
self.photoIndex++;
if (self.photoIndex >= [self.photos count]) {
self.photoIndex = 0;
}
__weak Photo *photo = [self.photos objectAtIndex:self.photoIndex];
[[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:photo.thumbnailURLString] options:SDWebImageRetryFailed progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
}];
}
.
왜이 코드가 유지주기를 유발합니까? 이 상황에서 자아를 다루기 위해 특별한 방법이 있습니까?
self.photos
는 NSMutableArray
self.photoIndex
가 NSInteger
SDWebImageManager
가 잘 유지 라이브러리입니다 : https://github.com/rs/SDWebImage 그리고 내가 어떤 문제가 표시되지 않습니다
속성에서'[SDWebImageManager sharedManager]'를 (를) 이동하려 했습니까? 그리고 코드를 완성 블록에 게시 할 수 있습니까? –
모든 이미지를 다운로드 한 후에 다운로드를 중지하는 대신 0 인덱스에서 이미지를 다시 다운로드하기 시작하는 이유는 매 시간 간격마다 타이머가이 메서드를 호출하기 때문에 해당 간격 내에서 순 속도가 느린 경우 이미지가 언젠가 다운로드되지 않습니다. –
@SaintThread 완료 블록에서 모든 코드를 제거했지만 여전히 메모리 누수가 발생합니다. – Cbas