저는 PhotoScrollerNetwork project을 사용하여 프로젝트의 뷰에 하나의 고해상도 이미지를 제공하고 자동으로 타일링하여 메모리를 올바르게 관리합니다. 이 코드 블록을 사용하여 전체 고해상도 이미지를 메모리로 가져 와서 타일을 계산할 수 있습니다. 클래스의 dealloc
방법에서 CGContextDrawImage 메모리가 해제되지 않았습니다
-(void)drawImage:(CGImageRef)image {
madvise(ims[0].map.addr, ims[0].map.mappedSize - ims[0].map.emptyTileRowSize, MADV_SEQUENTIAL);
unsigned char *addr = ims[0].map.addr + ims[0].map.col0offset + ims[0].map.row0offset * ims[0].map.bytesPerRow;
CGContextRef context = CGBitmapContextCreate(addr, ims[0].map.width, ims[0].map.height, bitsPerComponent, ims[0].map.bytesPerRow, colorSpace, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little);
assert(context);
CGContextSetBlendMode(context, kCGBlendModeCopy); // Apple uses this in QA1708
CGRect rect = CGRectMake(0, 0, ims[0].map.width, ims[0].map.height);
CGContextDrawImage(context, rect, image);
CGContextRelease(context);
madvise(ims[0].map.addr, ims[0].map.mappedSize - ims[0].map.emptyTileRowSize, MADV_FREE);
}
의 IMS는 ('무료 (IMS)') 해제, 그래서 이것은 적절하게 처리해야한다. 그러나 새로운보기 (그리하여 drawImage에 대한 호출)를 반복적으로 수행하면 내 기억이 채워질 것입니다. 나는 내가
CGContextDrawImage(context, rect, image);
을 주석하면 메모리가 괜찮다는 것을 알게되었는데, 그래서 뭔가가 메모리에 유지된다고 생각했지만, 나는 그것을 얻을 수 없다. dealloc 메소드는 항상 그렇게 불려서 문제가되지 않는다.
편집 : 내 이미지는이 전체 흐름입니다, 제대로 출시 :
- (void)myFunc {
CFDictionaryRef options = [self createOptions];
CGImageRef image = CGImageSourceCreateImageAtIndex(imageSourcRef, 0, options);
CFRelease(options);
CFRelease(imageSourcRef);
if (image) {
[self decodeImage:image];
CGImageRelease(image);
}
}
- (void)decodeImage:(CGImageRef)image {
assert(decoder == cgimageDecoder);
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
#if LEVELS_INIT == 0
zoomLevels = [self zoomLevelsForSize:CGSizeMake(width, height)];
ims = calloc(zoomLevels, sizeof(imageMemory));
#endif
[self mapMemoryForIndex:0 width:width height:height];
[self drawImage:image];
[self createLevelsAndTile];
}
왜 github 지원 링크에 질문을 게시하지 않으셨습니까? 그것의 아주 희박한 누군가는 (그러나 저, 프로젝트의 저자) SO에 당신의 질문에 응답 할 수있다 : -). 아마도 가장 좋은 방법은 변경된 프로젝트를 가져 와서 압축하여 드롭 박스 계정에 게시하면됩니다. 그래서이 프로젝트를 살펴볼 수 있습니다 (이번 주말까지는 그렇지 않을 수도 있음). –