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

查看:130
本文介绍了应用程序因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 Live Bytes。还在自动释放池中包含代码,但没有获得成功。我的代码

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天全站免登陆