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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:22:52+00:00 2026-06-04T06:22:52+00:00

I have a scrollview. I add a button to this scrollview and release it

  • 0

I have a scrollview. I add a button to this scrollview and release it after.

UIButton * saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
saveButton.frame = CGRectMake(415.0, 473, 80, 38);
saveButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:24];
[saveButton setTitle:@"" forState:UIControlStateNormal];
[saveButton setContentEdgeInsets:UIEdgeInsetsMake(2, 0, 0, 0)];
saveButton.backgroundColor = [UIColor clearColor];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
[saveButton setBackgroundImage:[UIImage imageNamed:@"save.png"] forState:UIControlStateNormal];
[saveButton addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
saveButton.hidden = NO;
[self.scrollview addSubview:saveButton];
[saveButton release];

The application crashes when the view appears on screen, and I try and touch any part of the screen.

If I comment out

[saveButton release];

the application works perfectly.

I thought the retain count of the button would be incremented once I add it to the scrollview so it would be safe for me to release the button.

What’s going on here? Is adding something to a scrollview not the same as adding it to the main view like below?

[self.view addSubview:saveButton];
  • 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-04T06:22:54+00:00Added an answer on June 4, 2026 at 6:22 am

    buttonWithType: is a convenience constructor, so it already creates an autoreleased instance, and there is no need to release the object.

    That means the following line of code is an error:

    [saveButton release];
    

    You should not send release, as the instance is already autoreleased.

    Check the UIButton reference for details.

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

Sidebar

Related Questions

I have a scrollview in which i am creating buttons programmatically. On touch, button
I am trying to add the UIButton to UIScrollView . I have added the
I got stuck in here, I have a custom scrollview in a view this
I have a ScrollView -> Table => TableRow that I dynamically add Rows to,
have this layout css: <?xml version=1.0 encoding=utf-8?> <ScrollView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/ScrollView01 android:layout_width=wrap_content android:layout_height=wrap_content android:scrollbars=vertical> <LinearLayout
i have added a UIViewController's view and a button to scrollview as subview...now how
I have a scrollView where I add some UIButtons and UIActivityIndicators in the main
I have this nice android app made up and was going to add in
I have add a view with button in UITableView Header . I have set
I have a scrollview control that has a StackPanel (Orientation=Vertical) UI Element inside of

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.