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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:48:52+00:00 2026-05-28T05:48:52+00:00

here I have a tableView in my viewController, and it’s like this: //.h …

  • 0

here I have a tableView in my viewController, and it’s like this:

//.h
...
UITableView *aTable;
...
@property (nonatomic, retain) UITableView *aTable;
//.m
@synthesize aTable;
...
self.aTable = nil; // in viewDidUnload
[aTable release];  // in dealloc
...

and now, in the viewDidLoad method I have to initialize this talbe, so I did this

// viewDidLoad
...
self.aTable = [[UITableView alloc] initWithFrame:xxxxx];
...

but when I analyze this, it reminds me that in the viewDidLoad,

there maybe a potential leak of memory of this “aTable”,

but I guess I am about to release it in the dealloc, so why is there still a leak of memory?

it is about the “retain” property?

do I have to add an autorelease to the code where alloc and initiate this tableView?

Thanks a lot!

  • 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-28T05:48:53+00:00Added an answer on May 28, 2026 at 5:48 am

    Yes, it should be (in a non arc environment):

    self.aTable = [[[UITableView alloc] initWithFrame:xxxxx] autorelease];
    

    This give you an autoreleased object (retain count: 0)

    [[[UITableView alloc] initWithFrame:xxxxx] autorelease];
    

    This retains the table(retain count: 1) in order to persist til viewDidUnload or til Dealloc

    self.aTable = ...
    

    If you dont autorelease the table you’re getting a retain count: 2 (One of the alloc-init and the other from the retain property), then on the ViewDidUnload with this line self.aTable = nil; you are decreasing the retaing count to 1, but then assigning nil to your ivar, so you’re lossing the reference to the alive table hence leaking the tableView, then in dealloc you will make basically this [nil release] which has no effect.

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

Sidebar

Related Questions

I have a UITableView which loads through it's navigationController a new viewcontroller. This code
I have a tableview inside a viewcontroller I would like to edit/delete rows. It
Here I have an arbitrary IEnumerable<T> . And I'd like to page it using
I have been trying to do this for a long time now. so here
I have declared this ivar in my ViewController.h #import <UIKit/UIKit.h> @interface FirstViewController : UIViewController
I have a ViewController with a nib which have a UIView and a UITableView
Here's my case: I have a table view showing contacts. Add button in the
I have encountered a problem of placing data into the Table View. Here is
Just wondering what little scripts/programs people here have written that helps one with his
Since upgrading to 2008 I and many people here have noticed that randomly VS

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.