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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:18:39+00:00 2026-05-23T04:18:39+00:00

This is probably a dumb question, but in the introduction to TableViews, the author

  • 0

This is probably a dumb question, but in the introduction to TableViews, the author has a property of NSArray *listData to fill the table with dummy data. In the viewDidLoad, he basically does this:

- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects@"1", @"2", @"3", more stuff, nil];
self.listData = array;
[array release];
...
}

Why does he create another array and set it to the property as opposed to doing something like

- (void)viewDidLoad {
listData = [[[NSArray alloc] initWithObjects@"1", @"2", @"3", more stuff, nil]autorelease];

Is it to manage memory better by using alloc/init vs the autorelease pool? Or is the second way just not going to work? Thanks.

  • 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-23T04:18:40+00:00Added an answer on May 23, 2026 at 4:18 am

    Your code is wrong and is likely to crash. In his code, he calls alloc, meaning the retain count is 1. He then assigns it to a property. I’m assuming this property is declared to be retain, in which case the retain count would go up to 2. He then called release, which drops the retain count back to 1.

    In your code, you call alloc, meaning the retain count is 1, then you call autorelease, which means that the retain count will drop to 0 and the object’s memory will be deallocated soon. You assign the object to an instance variable – not a retained property like he does – so you won’t increase the retain count any more. This means that you’ll be left with a dangling pointer to memory that could be overwritten with anything else at any time. When you try to access listData, you’ll crash because it is likely to have been overwritten.

    Please read Memory Management Programming Guide if you do not understand what is happening here.

    Having said that, the core of your question is valid. There’s nothing stopping him from doing the same as you, except assigning to a retained property instead of an instance variable.

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

Sidebar

Related Questions

This is probably a really dumb question with a simple answer but... I am
I'm very new to Java programming language so this is probably dumb question but
This is probably a dumb question but I can't find it anywhere... Which icon
this is probably a dumb question, but wasnt too sure what else to do.
sorry this is probably a dumb question, but I want to make the background
This is probably a dumb question but I'm just learning. If I have a
I know this is probably a dumb question but I can't figure it out
This is probably a dumb question, but I can't find a definitive answer anywhere.
This is probably a dumb question, but is it possible to use a type
This is probably a dumb question, but.. Any ideas how to insert BrowserCMS portlet

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.