'추가 루프'실행 전 할당
코드:
// loading items to the array, there are no memory warnings after this is completed. The first allocations screenshot is after this code and before extra loop code.
NSMutableArray *albumCovers = [[NSMutableArray alloc] init];
for (MPMediaQuery *query in queries) {
NSArray *allCollections = [query collections];
for (MPMediaItemCollection *collection in allCollections) {
MPMediaItemArtwork *value = [collection.representativeItem valueForProperty:MPMediaItemPropertyArtwork];
UIImage *image = [value imageWithSize:CGSizeMake(100, 100)];
if (image) {
[albumCovers addObject:image];
}
}
}
}
_mediaCollections = [NSArray arrayWithArray:artworkedCollections];
_albumCovers = [NSArray arrayWithArray:albumCovers];
}
그리고 다른 곳 :
// !!!!! extra loop - from here the memory starts to grow and never release
for (i=0; i< 800; i++) {
UIImage * coverImage = [_albumCovers objectAtIndex:indexPath.row];
[veryTemp setImage:coverImage]; // exactly this line adds to the memory. with this line commented, there is no problem.
}
'추가 루프'실행 후 할당
명확하게하기 위해 only-obj-c를 켜고 시스템 라이브러리를 끈 상태에서 스택을 호출하십시오 (이 기능을 켜면 가장 높은 %는 가장 무거운 메서드 당 0.9 %입니다)
나는 약간의 연구를했고 stackoverflow 에서 이것들 VM:ImageIO_PNG_Data
은 일반적으로에서 오는 것으로 나타났습니다 [UIImage imageNamed:]
. 그러나 당신이 볼 수 있듯이 나는이 방법을 사용하지 않고 단지에서 참조를 얻고 있습니다 MPMediaItemCollection
.
문제는 UIImage가 일반적으로 작은 ref (CGImageRef) 만 유지한다는 것입니다. 항목을 표시 한 후 CGImageRef에 정보가 '주입'되었습니다. 그 결과 테이블은 항상 커졌습니다.
간단하지만 가장 아름답지는 않은 해결책은 코드를 사용하는 것입니다.
NSArray = @[obj1, obj2, obj3]; // where obj is custom NSObject and has a UIImage property
대신에:
NSArray = @[img1, img2, img3]; // where img is of UIImage type
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다