iOS iPhone CG图像内存问题

iOS iPhone CG图像内存问题,iphone,ios,memory,cgimage,Iphone,Ios,Memory,Cgimage,我正在尝试创建我所拥有的一些数据的可视化表示 我拥有的功能可以完美地创建图像(而且非常快),但在仪器的作用下,实际内存使用量急剧上升,最终导致应用程序崩溃 我已将我的函数替换为返回[UIImage ImageName:@“blah”]和内存问题完全消失 我想知道是否有人能看到为什么和哪里的记忆被占用,以及我如何可能再次释放它 我已经在分配和泄漏工具下运行了仪器,但没有显示任何内容 功能是 - (UIImage*)imageOfMapWithDeadColor:(UIColor *)deadCol

我正在尝试创建我所拥有的一些数据的可视化表示

我拥有的功能可以完美地创建图像(而且非常快),但在仪器的作用下,实际内存使用量急剧上升,最终导致应用程序崩溃

我已将我的函数替换为返回[UIImage ImageName:@“blah”]和内存问题完全消失

我想知道是否有人能看到为什么和哪里的记忆被占用,以及我如何可能再次释放它

我已经在分配和泄漏工具下运行了仪器,但没有显示任何内容

功能是

- (UIImage*)imageOfMapWithDeadColor:(UIColor *)deadColor aliveColor:(UIColor *)aliveColor
{
//translate colours into rgb components
if ([deadColor isEqual:[UIColor whiteColor]]) {
    dr = dg = db = 255;
} else if ([deadColor isEqual:[UIColor blackColor]]) {
    dr = dg = db = 0;
} else {
    [deadColor getRed:&drf green:&dgf blue:&dbf alpha:&blah];

    dr = drf * 255;
    dg = dgf * 255;
    db = dbf * 255;
}

if ([aliveColor isEqual:[UIColor whiteColor]]) {
    ar = ag = ab = 255;
} else if ([aliveColor isEqual:[UIColor blackColor]]) {
    ar = ag = ab = 0;
} else {
    [aliveColor getRed:&arf green:&agf blue:&abf alpha:&blah];

    ar = arf * 255;
    ag = agf * 255;
    ab = abf * 255;
}

//create bytes of image from the cell map
int yRef, cellRef;

unsigned char *cell_ptr = cells;

for (int y=0; y<self.height; y++)
{
    yRef = y * (self.width * 4);

    int x = 0;
    do
    {
        cellRef = yRef + 4 * x;

        if (*cell_ptr & 0x01) {
            //alive colour
            buffer[cellRef] = ar;
            buffer[cellRef + 1] = ag;
            buffer[cellRef + 2] = ab;
            buffer[cellRef + 3] = 255;
        } else {
            //dead colour
            buffer[cellRef] = dr;
            buffer[cellRef + 1] = dg;
            buffer[cellRef + 2] = db;
            buffer[cellRef + 3] = 255;
        }
        cell_ptr++;
    } while (++x < self.width);
}

//create image
imageRef = CGImageCreate(self.width, self.height, 8, 32, 4 * self.width, CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault, provider, NULL, NO, kCGRenderingIntentDefault);

UIImage *image = [UIImage imageWithCGImage:imageRef];

//return image
return image;
}
-(UIImage*)带有死色的贴图的图像:(UIColor*)死色aliveColor:(UIColor*)aliveColor
{
//将颜色转换为rgb组件
如果([deadColor isEqual:[UIColor whiteColor]]){
dr=dg=db=255;
}否则如果([deadColor isEqual:[UIColor blackColor]]){
dr=dg=db=0;
}否则{
[deadColor getRed:&drf green:&dgf blue:&dbf alpha:&blah];
dr=drf*255;
dg=dgf*255;
db=dbf*255;
}
如果([aliveColor isEqual:[UIColor whiteColor]]){
ar=ag=ab=255;
}否则如果([aliveColor isEqual:[UIColor blackColor]]){
ar=ag=ab=0;
}否则{
[aliveColor getRed:&arf green:&agf blue:&abf alpha:&blah];
ar=arf*255;
ag=agf*255;
ab=abf*255;
}
//从单元格映射创建图像字节
int yRef,cellRef;
无符号字符*单元格\u ptr=单元格;

对于(int y=0;y,您使用CGImageCreate,文档说:

返回值
新的石英位图图像。您负责通过调用CGImageRelease来释放此对象。

您使用CGImageCreate,文档会说:

返回值
一个新的石英位图图像。您负责通过调用CGImageRelease来释放此对象。

太棒了!谢谢!我不知道我怎么会错过它。现在工作正常。(计时器用完时将接受正确答案)太棒了!谢谢!我不知道我怎么会错过它。现在工作正常。(计时器用完时,将接受正确答案)