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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:46:49+00:00 2026-05-24T22:46:49+00:00

I’ve read http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html#//apple_ref/doc/uid/TP40007457-CH101-SW19 but I’m still not completely clear on how this works. @property

  • 0

I’ve read http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html#//apple_ref/doc/uid/TP40007457-CH101-SW19 but I’m still not completely clear on how this works.

@property (nonatomic, retain) UIButton *startButton;
@property (nonatomic, retain) UITextView *infoTextView;

This is a view controller displayed in a tab bar

- (void)loadView
{
    UIView *newView = [[UIView alloc] init];

    //self.startButton and addSubivew retains the button obect; retain count = 2
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //autorelases
    self.startButton = button;
    [newView addSubview:startButton];    

    //addSubview retains infoTextView; self.infoTextview retains; retain count: 2
    self.infoTextView = [[[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, 280.0, 270.0)] autorelease];
   //autoreleased
    [newView addSubview:infoTextView];

    //View controller retains the view hierarchy
    self.view = newView;
    [newView release];

}


//customization of the button and textview (text, frame, center, target-action etc)
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self loadStartButton];
    [self loadTextView];

}

//because these have retain properties, they are released through nil
- (void)viewDidUnload
{
    self.startButton = nil;
    self.infoTextView = nil; //retain counts - 1
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc
{
    [startButton release];
    [infoTextView release]; //retain counts -1
    [super dealloc];
}

My question is this: should the UIView objects have retain counts of two? The way I see it is that the view controller retains the UIView object, and the viewController.view also retains the UIView object (through adding subviews). Is this the correct way to look at it conceptually? Because then my viewController is also managing objects owned by its .view property.

However, I’m not sure if both viewDidUnload and dealloc are called in the case of low memory situations. Am I releasing them correctly or setting up a memory leak?

(any comments about putting code in the wrong place would be helpful as well)

  • 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-24T22:46:51+00:00Added an answer on May 24, 2026 at 10:46 pm

    In a low-memory situation, I don’t think your view controller will be dealloc’ed. Your view will. viewDidUnload will be called but not dealloc. That’s ok. Your buttons will be freed. Both the reference from the view controller will be released, by your viewDidUnload code, and the reference from addSubview, by the view’s default dealloc code (or somewhere in default code).

    When you do deallocate your view controller, if ever, both will get called. The release statements in the dealloc will do nothing, because they will be equivalent to [nil release], which is a no-op. That’s ok.

    I think you can take the release statements out of the dealloc though, since dealloc should never get called without viewDidUnload getting called first.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.