gpt4 book ai didi

ios - CGContextDrawImage 内存未释放

转载 作者:行者123 更新时间:2023-12-01 16:53:25 25 4
gpt4 key购买 nike

我正在使用 PhotoScrollerNetwork project为我的项目中的 View 提供单个高分辨率图像并自动平铺它,以便正确管理内存。它使用此代码块将完整的高分辨率图像绘制到内存中,以便可以从中计算出图 block 。

-(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);
}

dealloc类的方法,ims 被释放('free(ims)'),所以应该正确处理。但是,如果我反复创建一个新 View (并因此调用 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];
}

最佳答案

运行本地 from-bundle 图像和网络图像,似乎任何重大泄漏都消失了。这适用于 iOS7 和 Xcode 5。

关于ios - CGContextDrawImage 内存未释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13835534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com