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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:47:44+00:00 2026-05-20T18:47:44+00:00

First time asking a question here. I have a question, I have a UIImageView

  • 0

First time asking a question here.

I have a question, I have a UIImageView added as a subview to my UIButton, which is declared using buttonWithType: (which means I don’t have to release the button right?) But do I still have to release the subview of my UIButton?

Code bits:

UIImage *circleImage = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"item-circle" ofType: @"png"]];
UIImageView *circleImageView = [[[UIImageView alloc] initWithImage: circleImage] autorelease];
[imageView setFrame: CGRectMake(-5, -5, 65, 65)];

UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
[button addSubview: circleImageView];
  • 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-20T18:47:44+00:00Added an answer on May 20, 2026 at 6:47 pm

    Short Answer:

    Your code seems fine. The basic rule of thumb is that for every alloc, new, retain, or copy, you need a release or autorelease.


    Long Answer:

    Let’s go through your code line by line.

    UIImage *circleImage = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle]  pathForResource: @"item-circle" ofType: @"png"]];
    

    This first line uses a convenience method. you don’t need to call release on anything, since you haven’t called alloc, new, retain, or copy.

    UIImageView *circleImageView = [[[UIImageView alloc] initWithImage: circleImage] autorelease];
    

    In the second line, you call alloc, but you then call autoerelease, so you’re good there.

    [imageView setFrame: CGRectMake(-5, -5, 65, 65)];
    

    Again, no alloc, new, retain, or copy.

    UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
    

    Once again, you’ve used a convenience method.

    [button addSubview: circleImageView];
    

    You still haven’t called alloc, new, retain, or copy. Therefore, you don’t call release or autorelease.

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

Sidebar

Related Questions

It's my first time asking here (I have visited the site several times, but
This is my first time asking a question, please be gentle! I have a
First time asking a question here. Usually I can find my answer without having
this is my first time asking a question here so apologies if I am
this is my first time asking a question here so I hope I am
First time asking a question here so thanks in advance for your time. I
Well this is not the first time im asking these question here but I
This is the first time i'm asking a question here at stack overflow so
first time posting here. I'm using a loop to create 3 buttons, but my
First time poster here. A quick question about setting up a loop here. I

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.