Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:55:59+00:00 2026-06-17T09:55:59+00:00

My app loops through array of image paths and merges all those images into

  • 0

My app loops through array of image paths and merges all those images into one. The code is below. However, the app crashes when I release the image with (gdb) printed out in my console. If I remove image release line, then it works fine but this may probably lead to memory leaks. Please look at this code and explain why this happens and what can be improved. Thank you.

UIGraphicsBeginImageContextWithOptions(CGSizeMake(width*len+padding*len+padding,
                                                  height+padding*2), 
                                       YES, 0.0);
do{

        //draw image
        path = (NSString*)[_imageData objectAtIndex:i];
        UIImage * img = [[[UIImage alloc] initWithContentsOfFile:path]
                           cropCenterAndScaleImageToSize:CGSizeMake(width, height)];
        [img drawAtPoint: CGPointMake(width*i+padding*i+padding,padding) blendMode:kCGBlendModeNormal alpha:1];
        [img release]; //APP CRASHES HERE BUT WORKS IF THIS LINE REMOVED
        i++;
    }while (i<len);
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(result, self,
                                   @selector(image:didFinishSavingWithError:contextInfo:),
                                   nil);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:56:00+00:00Added an answer on June 17, 2026 at 9:56 am

    The problem is that you are not releasing the allocated image. You are releasing the autoreleased cropped image and leaking the allocated image.

    Change this:

    UIImage * img = [[[UIImage alloc] initWithContentsOfFile:path]
                       cropCenterAndScaleImageToSize:CGSizeMake(width, height)];
    [img drawAtPoint: CGPointMake(width*i+padding*i+padding,padding) blendMode:kCGBlendModeNormal alpha:1];
    [img release];
    

    to:

    UIImage *original = [[UIImage alloc] initWithContentsOfFile:path];
    UIImage *cropped = [original cropCenterAndScaleImageToSize:CGSizeMake(width, height)];
    [cropped drawAtPoint:CGPointMake(width * i + padding * i + padding, padding) blendMode:kCGBlendModeNormal alpha:1];
    [original release];
    

    I’m assuming the cropCenterAndScaleImageToSize: is some category method that returns an autoreleased UIImage reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm filling a sitemap array as the user travels through my app. However my
Consider the following image: My app first finds all the blue pixels and also
i am use this code to upload image ..this code save uploads url into
I am looping through an array of file paths retrieved by a core data
i've an app that loops through a bitmap and places a distortion on it.
In the below code there's a loop that features all products under a given
In my Rails app, I loop through an array to create a list of
I'm making an app that converts images into textual RRR GGG BBB string arrays.
Hi there I have written a code that ietrates through whole array and copies
I've created an app that loops through two bitmaps and store the pixel data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.