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

The Archive Base Latest Questions

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

Until five minutes I was sure that my understanding about Objective c reference counting

  • 0

Until five minutes I was sure that my understanding about Objective c reference counting is excellent, but when I started checking objects retainCount I was very surprised to see what I saw.

For example myViewController has a UITableview:

.h file

@interface RegularChatViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
     UITableView *_tableView;
}
@property (nonatomic, retain) IBOutlet UITableView *tableView; 

.m file

@synthesize tableView = _tableView;

- (void)loadView
{
    _tableView = [[UITableView alloc] init];  // STEP ONE
    NSLog(@"tableView retain count: %d",[_tableView retainCount]);

    self.tableView.frame = CGRectMake(0, 0, 320, tableHeight); // STEP TWO
    NSLog(@"tableView retain count: %d",[_tableView retainCount]);  

    [self.view addSubview:self.tableView]; // STEP THREE
    NSLog(@"tableView retain count: %d",[_tableView retainCount]); 
}

To my surprise the input was:

tableView retain count: 1
tableView retain count: 2
tableView retain count: 3

obviously STEP ONE increase retain count by 1 with alloc

I also know that STEP THREE increase retain count by 1 with addSubview

But whats going on in STEP TWO ??? why did it increase the retain count???
is there something to do with ARC??

  • 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-04T15:53:26+00:00Added an answer on June 4, 2026 at 3:53 pm

    According to Apple docs on NSObject Protocol Reference for the retainCount method:

    Important This method is typically of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.

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

Sidebar

Related Questions

Until recently, I believed that the .NET runtime only increases the reference count of
I have a process that runs on cron every five minutes. Usually, it takes
I have a pretty basic page that shows every five minutes of the day
Until yesterday everything was normal but today i try to lauch my application using
Until now I've been only writing console applications but I need to write a
I have a jQuery application that loads data from five asynchronous server calls. I
I have a client TCP socket that writes a few bytes every five seconds,
I wrote a heredoc three weeks ago that was working great, and until today
I have an unusual need. I have five input checkboxes that look like this:
I have a cronjob which commits some files every five minutes. However, it is

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.