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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:43:37+00:00 2026-05-27T00:43:37+00:00

I have been working with Objective-C for a month approximately but regretfully I’m still

  • 0

I have been working with Objective-C for a month approximately but regretfully I’m still a complete dummy in memory management so I need your advice. I pass an array from one file to the other like this

         BidView *bidView = [[[BidView alloc] init] autorelease];
         NSLog(@"%i",[bidView.seatsForTableCreated retainCount]);
         bidView.seatsForTableCreated = [NSArray arrayWithArray:seats];
         NSLog(@"%i",[bidView.seatsForTableCreated retainCount]);
         [self.navigationController pushViewController:bidView animated:YES];  `

NSLog tells me that retain count of seatsForTableCreated has raised from zero to two. Then, when I quit the BidView screen (without doing anything with seatsForTableCreated array) I’ m doing the following:

NSLog(@"%i",[seatsForTableCreated retainCount]);
[seatsForTableCreated release];
NSLog(@"%i",[seatsForTableCreated retainCount]);

it’s quite unclear for me. Now NSLog tells me (both times) that retain count is 1. Then I repeat this procedure (running the same application I mean) and each time things are the same:0-2-1-1. So my questions are:
1)Why 0 to 2? Why retain count increases to 2 not to 1?
2)why then it drops to 1 without being impacted in any way?
3)Why it still remains 1 after i’ve released it?
4)How would you manage the memory in such a case?
Great thanks in advance

  • 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-27T00:43:37+00:00Added an answer on May 27, 2026 at 12:43 am

    My advice assumes you are using Xcode 4+ and you are not using ARC,

    command+shift+B will analyse your memory management (and dead stores and such). I think you got it right. Don’t worry about the retain counts so much until you get a complaint from Analyze or find leaks with Instruments. I am not sure how reliable retain counts are. I have seen comments on SO saying not to rely on them.

    You are following the rules well
    New, Alloc, Copy, Retain –> You will need to release this object when you are done with it.

    I am also assuming in BidView.h your property is declared as
    @property(nonatomic, retain) NSArray * seatsForTableCreated;

    So releasing that in the dealloc method in BidView.m is good memory management

    EDIT
    It works when even though you don’t allocate seats for table created because.
    self.seatsForTableCreated = ... will retain whatever object you are setting there.
    So if you have a property with (retain) in the declaration, you can consider

    self.property = object;
    

    as setting property and retaining it. The properties were added to objective-C to reduce similar code being in every class.

    A property in .h

    @property (nonatomic,retain) NSObject * property; // don't name your properties property..
    

    Compiler will create 2 methods for you automatically when you @synthesize in the .m

    -(void)setProperty:(NSObject*)newP
    {
        [newP retain];  // retains the new object so it sticks around for line 3
        [property release]; // releases previous property
        property = newP; // set the property to the object retained in line 1
        // property is now same as newP and you are responsible for releasing it
        // -(void) dealloc   is where you should release it
    }
    

    // Note, the compiler may not create the exact same code as above when creating the //setProperty method. If it does, it could be subject to change.

    -(NSObject*)property
    {
        return property;
    }
    

    I tried to figure out why Analyze isn’t catching the issue when you don’t release your property, but haven’t. That is confusing and I want to explore it further.

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

Sidebar

Related Questions

I have been working on a project on and off, but I haven't touched
I have been working on a simple text editor in Cocoa/Objective-C for a practice
For a long time I have been working with ReSharper. But after seeing CodeRush
I'm new to Objective-C and I have been working with simple programs, and I
I have been working with InputStreams in Objective-C and seem to have taken the
I have been working with Objective C for a few months now and feel
I've been playing with Objective-C the past couple of weeks and have a working
I have been working with Objective C for a couple of months now and
Have been working on this question for a couple hours and have come close
I have been working with SQL Server as a Developer a while. One thing

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.