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

  • Home
  • SEARCH
  • 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 6172571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:25:04+00:00 2026-05-23T23:25:04+00:00

I had a super noob question about assigning objects in objective-c. I basically am

  • 0

I had a super noob question about assigning objects in objective-c. I basically am trying to create an array of thumbnails to use. I have this code from another post.

+ (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}

In my viewDidLoad, I do this:

// Create thumbnail images to be used in UITableView.
    NSMutableArray *imageArray = [[NSMutableArray alloc] initWithCapacity:[_list count]];  // list is an array that has my data
    for (id *test in _list) {
        UIImage *cardImage = [UIImage imageNamed:test.ImageFile];  // line 1
        cardImage = [UIImage scale:cardImage toSize:CGSizeMake(50, 50)];  // line 2
        [imageArray addObject:cardImage];  // line 3
    }
    self.List = imageArray;
    [imageArray release];

My question is in regards to inside the for loop. This is my understanding of how it works, please correct me if I’m wrong.

Line 1 creates an autorelease UIImage called cardImage.

Line 2 creates another UIImage from the scale:toSize: method. (I’m not sure if this UIImage is autoreleased or not). cardImage now points to this new UIImage created in line 2 and the autoreleased UIImage from line 1 will later be cleaned up.

Line 3 adds that new object to imageArray.

I wasn’t sure if this was right/wrong/good/bad, etc. I know with primitive types in a method, you can do

int x = 5;
x = 10;

But I wasn’t sure if I was creating a memory leak here by doing this, and if there was a better method. Thanks a bunch!

  • 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-05-23T23:25:06+00:00Added an answer on May 23, 2026 at 11:25 pm
    + (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
    {
        ...
        UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
        ...
        return scaledImage;
    }
    

    UIGraphicsGetImageFromCurrentImageContext returns an autoreleased image so does scale:toSize:. Therefore, your loop does not leak.

    Your first clue could have been the name: scale:toSize:. According to the Memory Management Rules, only methods whose names begin with “alloc”, “new”, “copy” or “mutableCopy” return objects you own. Other methods return objects you do not own.

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

Sidebar

Related Questions

I'm trying to learn the super() function in Python. I thought I had a
I have been struggling trying to test a super simple EJB project in netbeans.
I had asked a question similar to this before, but I have a new
I just started to learn Django and I had a question. I'm trying to
Had an interesting discussion with some colleagues about the best scheduling strategies for realtime
I had to delete all the rows from a log table that contained about
I had to use a Microsoft Web Services Enhancements 2.0 service and it raised
ok guy I really need you super brain on this, I had pull out
I had an argument with a colleague about writing python efficiently. He claimed that
Here’s a really really super-basic question. Say I wanted to build – today –

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.