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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:40:53+00:00 2026-05-21T18:40:53+00:00

Can anyone tell me how to release the image which is used as background

  • 0

Can anyone tell me how to release the image which is used as background image in UIButton. I created Custom button using following code but i could not able to release the memory of UIImage which is set a background image in the UIButton. Here is code which i used to create UIButton

`

   for (int index=0;index<10; index++)

   {            
    UIImage *image=[[UIImage alloc] initWithData:imageData];


    CGRect frame = CGRectMake(xValue, 10, 50, 50);  
    UIButton *button = [[UIButton alloc] initWithFrame:frame];

    [button addTarget:self action:@selector(onClickImgButton:)forControlEvents:UIControlEventTouchUpInside];
    [button setTag:index];      
    [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];     
    [button setImage:image forState:UIControlStateNormal];                      
    [button.layer setCornerRadius:10.0f];
    [button.layer setMasksToBounds:YES];
    [button.layer setBorderWidth:3.0f];
    [button.layer setBorderColor:[[UIColor lightGrayColor] CGColor]];

    image=nil;
    [image release];


    [horizontalScrollView addSubview:button];
    button=nil; 
    [button release];


    xValue=xValue+60;
    cx +=60;
}

`

  • 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-21T18:40:53+00:00Added an answer on May 21, 2026 at 6:40 pm

    First, you mixed your
    image=nil;
    [image release];

    order, you should first release, than set the pointer to nil. Right now you’re sending “release” to nil and nothing happens. You’re doing the same for the button btw.

    Now if you want the image to be freed from memory, you can’t do it as long as it’s being used by the button. So you’ll have to either free the button from memory (in this case by fixing the release and setting the pointer to nil, and removing the button from it’s superview) or do

    [button setImage:nil forState:UIControlStateNormal];
    

    Should set the retain count to 0 and eventually dealloc the image

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

Sidebar

Related Questions

Can anyone tell me why the following code fails to submit the form into
Can anyone tell me, how to make shadow, using UIPageViewController, around of my background
Can anyone tell me why is NSAutoreleasePool leaking in this code. I am using
Can anyone tell me why this code would not be working? $('body').on('test', function() {
can anyone tell me how to select data by date in MS.ACCESS database using
Can anyone tell me how to identify a particular background process (i.e., Already running
I am not getting my image working. Can anyone tell me what I am
Can anyone tell me the difference between [self.property release] and [property release] . I
Can anyone tell me what is going wrong with this code? I tried to
Can anyone tell the block animation equivalent of this below code snippet? [UIView beginAnimations:@View

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.