Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios iPad 3内存警告导致应用程序崩溃_Ios_Objective C_Ipad_Uiimageview_Uiimage - Fatal编程技术网

Ios iPad 3内存警告导致应用程序崩溃

Ios iPad 3内存警告导致应用程序崩溃,ios,objective-c,ipad,uiimageview,uiimage,Ios,Objective C,Ipad,Uiimageview,Uiimage,我在UIImage上画线,我的图像在UIImageView中。第一次绘图过程正常,我将新图像分配给UIImageView,但当我重复该过程时,它会给我内存警告,应用程序崩溃: 响应篮板的终止而终止 我已经分析了我的应用程序,CG光栅数据占用了273MB,总的来说是341MB的活动字节。也在自动释放池中包装了代码,但没有成功。我的代码 UIGraphicsBeginImageContext(imageView.image.size); [imageView.image drawAtPoint:C

我在
UIImage
上画线,我的图像在
UIImageView
中。第一次绘图过程正常,我将新图像分配给
UIImageView
,但当我重复该过程时,它会给我内存警告,应用程序崩溃:

响应篮板的终止而终止

我已经分析了我的应用程序,CG光栅数据占用了273MB,总的来说是341MB的活动字节。也在自动释放池中包装了代码,但没有成功。我的代码

UIGraphicsBeginImageContext(imageView.image.size);

[imageView.image drawAtPoint:CGPointMake(0, 0)];


context2=UIGraphicsGetCurrentContext(); 
for(int i=0; i<kmtaObject.iTotalSize; i++)
    {
        kmtaGroup=&kmtaObject.KMTA_GROUP_OBJ[i];

        //NSLog(@"Group  # = %d",i);

        for (int j=0; j<kmtaGroup->TotalLines; j++)
        {

            lineObject=&kmtaGroup->Line_INFO_OBJ[j];

           // NSLog(@"Line # = %d",j);
           // NSLog(@"*****************");
            x0 = lineObject->x0;
            y0= lineObject->y0;
            x1= lineObject->x1;
            y1= lineObject->y1;
            color= lineObject->Color;
            lineWidth= lineObject->LinkWidth;
            lineColor=[self add_colorWithRGBAHexValue:color];
            linearColor=lineColor;

            // Brush width
            CGContextSetLineWidth(context2, lineWidth);
            // Line Color
            CGContextSetStrokeColorWithColor(context2,[linearColor CGColor]);


            CGContextMoveToPoint(context2, x0, y0);

            CGContextAddLineToPoint(context2, x1, y1);
            CGContextStrokePath(context2);

        }
    }


    newImage=UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
    imageView.image=newImage;
UIGraphicsBeginImageContext(imageView.image.size);
[imageView.image drawAtPoint:CGPointMake(0,0)];
context2=UIGraphicsGetCurrentContext();
对于(int i=0;i线信息对象[j];
//NSLog(@“Line#=%d”,j);
//NSLog(@“*******************”);
x0=线对象->x0;
y0=线条对象->y0;
x1=lineObject->x1;
y1=线条对象->y1;
颜色=线条对象->颜色;
lineWidth=lineObject->LinkWidth;
lineColor=[使用RGBAhexValue:color自添加颜色];
linearColor=lineColor;
//刷子宽度
CGContextSetLineWidth(context2,线宽);
//线条颜色
CGContextSetStrokeColorWithColor(context2[linearColor CGColor]);
CGContextMoveToPoint(context2,x0,y0);
CGContextAddLineToPoint(context2,x1,y1);
CGContextStrokPath(context2);
}
}
newImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
image=newImage;

iOS设备中使用的最大分辨率为1024x1024。我们不能使用超过该大小的图像。使用2x和3x图像作为各自的设备大小。

因此,我碰巧遇到了类似的问题。我将图像分配给图像视图,其中图像本身先前由其他对象保留,正在处理,等等……结果图像视图确实以某种方式泄露了所有这些图像

我使用的解决方案是在将图像分配到图像视图之前,在
CGImage
级别创建图像副本。我猜位图或其他方面一定有问题。无论如何,请尝试创建这样的副本:

CGImageRef cgCopy = CGImageCreateCopy(originalImage.CGImage);
UIImage *copiedImage = [[UIImage alloc] initWithCGImage:cgCopy scale:originalImage.scale orientation:originalImage.imageOrientation];
    CGImageRelease(cgCopy);
imageView.image = copiedImage;

当设置动画时,您是否加载了任何图像?@VineeshTP是的,我正在加载高分辨率图像…我的循环绘制了图像上的所有线条。图像分辨率为7000X4000。循环结束后,我将图像指定给UIImageView。@VineeshTP但在我的情况下,我不能影响图像大小。还有什么解决方案吗?我看不出有任何问题h您发布的代码。您是否可以尝试通过注释掉您发布的最后一行(将图像分配到图像视图)来检查图像是否对此负责。您将看不到结果,但执行将完全相同,因此请检查它是否仍然泄漏内存。您是正确的。您可以或多或少地复制代码并将其放入另一个视图的drawRect方法中(覆盖它)。您需要添加的是绘制一个全屏矩形,填充颜色设置为“清除颜色”。同时删除所有与图像相关的代码。然后需要将此视图添加到图像视图(或滚动视图)中。此外,每次更改线条后,您都需要调用setNeedsDisplay在绘制线条的视图上显示。这不是因为我投了反对票,而是这个答案在很多方面都是错误的。2x和3x是用于从资源文件夹中获取适当图像资源的后缀,仅此而已。此外,内容比例为1x、2x、3x,仅用于呈现当使用帧、边界时,请使用视图坐标系。这与图像大小无关。关于1024x1024,您是否有任何参考,因为这与实际情况相差甚远。我尝试过您的解决方案:我的应用程序仍然崩溃,只有一件事发生了变化,它在执行大量迭代后崩溃n、 在正常情况下,它可以正常工作。非常感谢您的帮助,因此这可能已经解决了图像视图问题?其他地方可能存在另一个漏洞。您可以尝试注释图像分配和图像复制部分,看看您是否因“大量迭代”而导致崩溃。