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 5843797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:12:15+00:00 2026-05-22T12:12:15+00:00

I am adding an image to the first cell in a UITableView cellForRowAtIndexPath like

  • 0

I am adding an image to the first cell in a UITableView cellForRowAtIndexPath like so:

if (row == 0) {
        UIImage *image = [UIImage imageNamed:@"numberOneIcon.png"];
        //create a framework for the ui image view
        CGRect frame = CGRectMake(10, 37, image.size.width, image.size.height);
        //initialize the ui image view
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
        imageView.image = image;

        [cell.contentView addSubview:imageView];
        [image release];
        //[imageView release];
}

If I uncomment out the [imageView release]; it will crash when you ‘close’ the app (press the home bttn) then return to the app and return to the view with the UITableView in it.

If I leave this commented it doesn’t crash but am I not leaking memory here? If so is there another way to do this so as not to leak.

Many thanks

  • 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-22T12:12:16+00:00Added an answer on May 22, 2026 at 12:12 pm

    You should be releasing imageView rather than image. Change that code to the following:

    [cell.contentView addSubview:imageView];
            //[image release];
            [imageView release];
    

    You do not own image as you did not create it with alloc, new, nor did you retain it, thus you are not supposed to be releasing it. You did alloc an instance of imageView however, so that is what you release. I strongly recommend reading this.

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

Sidebar

Related Questions

I'm adding an Image View in Interface Builder with a transparent PNG (A logo
I'm subclassing UITableViewCell and adding two subviews (image, UILabel). When the row is touched.
in my app i have a table view and i am adding 4 image
I'm adding different text to each cell in UITableView. However when I do that,
I have problem with adding image to DGV cell after data binding. this is
I am dynamically adding an image to a canvas object which was working for
I am facing a problem in adding an image at the end of the
i am having a problem in adding the image files to project namespace. I'm
I am adding a custom background image to my navigation bar by creating an
I am adding two UIBarButtonItems to a UINavigationBar. The first of these is a

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.