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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:41:32+00:00 2026-05-14T16:41:32+00:00

Say I have a tableview class that lists 100 Foo objects. It has: @property

  • 0

Say I have a tableview class that lists 100 Foo objects. It has:

@property (nonatomic, retain) NSMutableArray* fooList;

and I fill it up with Foos like:

self.fooList = [NSMutableArray array];
while (something) {
  Foo* foo = [[Foo alloc] init];
  [fooList addObject:foo];
  [foo release];
}

First question: because the NSMutableArray is marked as retain, that means all the objects inside it are retained too? Am I correctly adding the foo and releasing the local copy after it’s been added to the array? Or am I missing a retain call?

Then if the user selects one specific row in the table and I want to display a detail Foo view I call:

FooView* localView = [[FooView alloc] initWithFoo:[self.fooList objectAtIndex:indexPath.row]];  
[self.navigationController pushViewController:localView animated:YES];
[localView release];

Now the FooView class has:

@property (nonatomic, retain) Foo* theFoo;

so now BOTH the array is holding on to that Foo as well as the FooView. But that seems okay right? When the user hits the back button dealloc will be called on FooView and [theFoo release] will be called. Then another back button is hit and dealloc is called on the tableview class and [fooList release] is called.

You might argue that the FooView class should have:

@property (nonatomic, assign) Foo* theFoo;

vs. retain. But sometimes the FooView class is called with a Foo that’s not also in an array. So I wanted to make sure it was okay to have two objects holding on to the same other object.

  • 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-14T16:41:33+00:00Added an answer on May 14, 2026 at 4:41 pm

    As others say, what you are doing is correct, and the code looks correct to me. I have tens of references to the same object in my code and as long as I have balanced all the retains and releases, everything works fine.

    To add a bit more detail… you ask:

    because the NSMutableArray is marked as retain, that means all the objects inside it are retained too?

    These are two different things. All collection classes (Dictionaries, Arrays, Sets) automatically retain things that you add to them, and release their content objects when the collection object is deallocated. (In case of NSMutableArray, the content object gets released either if you remove it individually from array, or when you deallocate the whole array.)

    This has nothing to do with whether the collection object itself is retained or assigned as a property. The only thing to consider there is that if your policy for the collection object property is not correct, it might get released sooner or later than you think and things may get out of balance.

    As others say… read the memory management guide, and practice. 🙂 Oh, and read other people’s code too from this perspective and try to understand how/why they are doing their memory management.

    One other small thing… for every retained property, make sure you have a release call in the object’s dealloc method.

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

Sidebar

Ask A Question

Stats

  • Questions 438k
  • Answers 438k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No. params just creates an array that contains the parameters… May 15, 2026 at 4:29 pm
  • Editorial Team
    Editorial Team added an answer Using LINQ and using lambdas are two different issues, though… May 15, 2026 at 4:29 pm
  • Editorial Team
    Editorial Team added an answer You should use new, not malloc. new throws std::bad_alloc when… May 15, 2026 at 4:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.