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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:48:12+00:00 2026-05-15T01:48:12+00:00

I have a newbie question about the following: – (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

  • 0

I have a newbie question about the following:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSArray *anArray;
    anArray = [dictionary objectForKey: [NSString stringWithFormat:@"%d", section]];
    //here dictionary is of type NSDictionary, initialized in another place.
    AnObject *obj = [[AnObject alloc] init];
    obj = [anArray objectAtIndex:0];
    [anArray release];
    return obj.title;
}

If I run it as it is I will get an error.
If I don’t put [anArray release] it works just fine.
I don’t quite understand why is this happening?

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-15T01:48:13+00:00Added an answer on May 15, 2026 at 1:48 am

    You absolutely must read and understand the Cocoa Memory Management Rules, in particular the fundamental rule which states:

    You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message. You are responsible for relinquishing ownership of objects you own using release or autorelease. Any other time you receive an object, you must not release it.

    Now, look at how you got hold of anArray. You used the method objectForKey: It does not start with alloc, nor new, nor does it contain copy. Nor have you retained anArray. Therefore, you do not own anArray. You must not release it.

    The above quoted rule is the most important thing to know about programming with Cocoa on the iPhone or Mac without garbage collection. One of the other posters here came up with the acronym NARC (New Alloc Retain Copy) as an aide memoire which is quite handy.

    Let’s apply the rule to the variable called obj in your code. You obtained that with a call to alloc, therefore you are responsible for releasing it. However, you then obtained it again (overwriting the previous value) with a call to objectForIndex: so after this you must not release it. However, the first value did need releasing and has now leaked. in fact, the alloc line is unnecessary.

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

Sidebar

Related Questions

Following up on my previous newbie question about Paypal , I have a new
I have a newbie question about integrating two iOS apps. I have created an
I'm a Ruby newbie. Have a very basic question about static and instance variables.
I have a newbie question regarding when to release the elements of a NSArray.
i'm a pl/sql newbie. now i have a question about oracle type . i
I have started using Yii framework and I have a -newbie- question about the
I am thinking about question in routing... I have for example following in URL:
I have a newbie question about how to assign class member (setter). I am
I have a newbie question about EF4. Let's say I have in my EDMX
I have a newbie question about Git: I need to move back and forth

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.