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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:58:41+00:00 2026-06-07T13:58:41+00:00

I dynamically add a subview to another uiview; in the subview ,click a button

  • 0

I dynamically add a subview to another uiview;

in the subview ,click a button to go back by the following method:

[self removeFromSuperView ];

but after manny times added subview and removed it,my app could crash ,the log said it was killed .

I found that calling [self removeFromSuperView] didn’t release self. So what’s the best methods to releas it?

  • 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-07T13:58:42+00:00Added an answer on June 7, 2026 at 1:58 pm

    If you are retaining the UIView on creation (or adding it to an array) the retain count will increase. For example:

    // Retain count is 1
    UIView *myView = [[UIView alloc] initWithFrame:myFrame];
    
    // Retain count is 2
    [myParentView addSubview:myView];
    
    // Retain count is 1 again
    [myView removeFromSuperView];
    

    In the above example you can autorelease the view if it is immediately added as a subView or release it in your dealloc if it is an iVar.

    EDIT: (other reasons your view could be retained)

    // Retain count +1
    [myArray addObject:myView];
    
    // Retained in the setter created by the @synthesize directive
    @property(nonatomic, retain) UIView *myView;
    

    Anything else that states in the documentation that the property is retained.

    You should also be careful of creating objects in the loadView method of a VC, if you do make sure you release them, as they will be created again when the loadView is called. This will happen if you VC’s view is unloaded and then reloaded.

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

Sidebar

Related Questions

so in my app, i click a button and i dynamically add a UITextField:
I want to dynamically add .Select statements, but the compiler will only allow me
Im looking to dynamically add some content to container after a certain tag,please have
I want to load a view dynamically on click of a button. Lets say
In my didSelectRowAtIndexPath I have the following: [self.table beginUpdates]; sideSwipeView = [[[UIView alloc] initWithFrame:CGRectMake(0,
I add a view dynamically, but when it appears on the form, it's in
i am creating button dynamically. and creation action methods by [newButton addTarget:self action:@selector(goToNew:)forControlEvents:UIControlEventTouchUpInside]; i
I wanna add a UITableView to UITableViewCell dynamically, when i click on the UITableViewCell
I want to dynamically add threading.Thread classes to a thread queue based on a
I am trying dynamically add children DIV under a DIV with ID=prnt. Addition 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.