2

My problem is when I assign the image which was returned by the UIGraphicsGetImageFromCurrentImageContext() , to the UIImageView more than once, my app crashes. Here is my code: If omit the assignment line of UIImageView app will not crash.

 UIImage *   newImage3;  
   UIGraphicsBeginImageContext(duplicateImage.size);

            [duplicateImage drawAtPoint:CGPointMake(0, 0)];


            context2=UIGraphicsGetCurrentContext();

            for(int k=0; k<kmtaGroup->TotalLines; k++)
            {
                lineObject=&kmtaGroup->Line_INFO_OBJ[k];
                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);


            }



             newImage3=UIGraphicsGetImageFromCurrentImageContext();

        }

              imageView.image=newImage3;

             UIGraphicsEndImageContext();
iOS_Learner
  • 159
  • 9
  • 1
    Will please share code ? and OS version running on iPad3 – Jageen Feb 06 '15 at 05:34
  • please post your code and crash logs – SeanChense Feb 06 '15 at 05:34
  • @Jageen posted the code. – iOS_Learner Feb 06 '15 at 05:46
  • @SeanChense how can I get the crash logs and post here ? – iOS_Learner Feb 06 '15 at 05:46
  • @Jageen , I have noticed one thing , that is If I perform this task with delay of few seconds then app doesn't crash immediately , though it gives memory warning repeatedly – iOS_Learner Feb 06 '15 at 05:53
  • @Farrukh it may be memory leak did you try this ?http://stackoverflow.com/questions/5121120/uigraphicsgetimagefromcurrentimagecontext-memory-leak-pdf-previews – Jageen Feb 06 '15 at 06:08
  • @Farrukh i think same question http://stackoverflow.com/questions/11578934/memory-warning-and-crash-arc-how-to-identify-why-its-happening – Jageen Feb 06 '15 at 06:12
  • How many lines are you drawing in that loop? – Lyndsey Scott Feb 06 '15 at 06:14
  • @Jageen yes I have been through from these two posts .. but did't work for me ... tried different solutions as suggested by the experts on this these posts. – iOS_Learner Feb 06 '15 at 06:16
  • @LyndseyScott it depends upon the touched location. sometimes i have to draw one line and some time I draw 60 lines.... – iOS_Learner Feb 06 '15 at 06:17
  • @LyndseyScott but I don't think so its an issue of drawing lines. – iOS_Learner Feb 06 '15 at 06:24
  • @Farrukh please check this demo i tried with your code, i could not reproduce memory warning or crash https://drive.google.com/file/d/0B4KnvB_2930aZnJmTVhyREtXdjA/view?usp=sharing – Jageen Feb 06 '15 at 06:42
  • @Jageen ok , let me check. – iOS_Learner Feb 06 '15 at 06:49
  • @Jageen did you try this code on the device ? because in my case my app goes fine in the simulator but on device it crashes – iOS_Learner Feb 06 '15 at 06:55
  • @Jageen thanks for your efforts. I have run your code on device also ... it doesn't crash. in my case images are very high in resolution e.g. 7000X4000. but you are not using any image. similarly you have just created a demo project and I am running the complete application. so help me to understand this issue with some other way. – iOS_Learner Feb 06 '15 at 07:10
  • @Farrukh will you share that image ? or create sample code like me which reproduce crash – Jageen Feb 06 '15 at 07:14
  • @Jageen Well I can't share the image, because in my app I am creating the image from the data and that data is placed on the server...and I have posted my code already. In my near nothing is wrong with the code. – iOS_Learner Feb 06 '15 at 07:28
  • @Jageen problem is related to UIGraphicsGetImageFromCurrentImageContext() returned image. – iOS_Learner Feb 06 '15 at 07:29
  • @Jageen or it could be an issue of multiple calling of this method in my app. because it gives me memory warning on the second call . and then crash occurs. – iOS_Learner Feb 06 '15 at 07:30
  • @Farrukh OK i will try to reproduce it, but it did not crash even if i click many time on "button" in my demo application. – Jageen Feb 06 '15 at 08:18
  • @Jageen you are right. your demo app doesn't crash, no matter how many times you call the method. – iOS_Learner Feb 06 '15 at 08:53
  • @Jageen another important behaviour which I observed now that is , if image is zoomed in then it doesn't give me any memory warning and app goes fine superbly... I fail to understand what's going on ... :( No matter how many times I call the method. – iOS_Learner Feb 06 '15 at 09:19
  • @Jageen when I get memory warning it gives me statement on app crash "Terminating in response to backboard's termination" . – iOS_Learner Feb 06 '15 at 09:57

0 Answers0