由于 iPad 3 上的内存警告,应用程序崩溃 [英] App crashes due to memory Warning on iPad 3

查看:23
本文介绍了由于 iPad 3 上的内存警告,应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am drawing lines on UIImage and my image is in UIImageView. First time drawing process goes fine and I assign the new Image to UIImageView but when I repeat the process it gives me memory warning and app crashes:

响应篮板的终止而终止.

Terminating in response to backboard's termination.

我分析了我的应用程序,CG 栅格数据占用了 273 MB,总共占用了 341 MB 实时字节.还将代码包装在自动释放池中,但没有成功.我的代码

I have profiled my app and the CG raster data was taking 273 MB and overall its 341 MB Live Bytes. Also wrapped code in in autorelease pool but didn't get the success. My Code

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;

推荐答案

所以我偶然发现了一个类似的问题.我将图像分配给图像视图,其中图像本身之前由其他对象保留,正在处理等等......结果是图像视图确实以某种方式泄漏了所有这些图像.

So it just happened I stumbled onto a similar issue. I was assigning an image to the image view where the image itself was previously retained by other objects, being processed and such... The result was that the image view did indeed leak everyone of those images somehow.

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

The solution I used was to create a copy of the image on the level of the CGImage before assigning it to the image view. I guess there must be an issue with the bitmaps or something. Anyway try creating a copy like this:

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

这篇关于由于 iPad 3 上的内存警告,应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆