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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:56:00+00:00 2026-06-08T07:56:00+00:00

I encounter an error when I run this program from Chapter 8 of Cocoa

  • 0

I encounter an error when I run this program from Chapter 8 of Cocoa Programming for Mac OSX by Aaron Hillegass.
The program binds a tableview to an array controller. In the setEmployees method of the array controller,

-(void)setEmployees:(NSMutableArray *)a
{
    if(a==employees)
        return;
    [a retain];//must add
    [employees release]; //must add
    employees=a;
}

In the book, the two retain and release statements were not included and my program crashes whenever I try to add a new employee. After googling I found these two must-add statements to prevent program crashing.
I do not understand the memory management here. I am assigning a to employees. Why must I retain a if I am not deallocating anything? Why can I release employees before using it in the last assignment statement?

  • 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-06-08T07:56:02+00:00Added an answer on June 8, 2026 at 7:56 am

    This is the standard pattern for setters using Manual Reference Counting (MRC). Step by step, this is what it does:

    -(void)setEmployees:(NSMutableArray *)a 
    { 
        if(a==employees) 
            return;          // The incoming value is the same as the current value, no need to do anything. 
        [a retain];          // Retain the incoming value since we are taking ownership of it
        [employees release]; // Release the current value since we no longer want ownership of it
        employees=a;         // Set the pointer to the incoming value
    } 
    

    Under Automatic Reference Counting (ARC) the accessor can be simplified to:

     -(void)setEmployees:(NSMutableArray *)a 
        { 
            if(a==employees) 
                return;          // The incoming value is the same as the current value, no need to do anything. 
            employees=a;         // Set the pointer to the incoming value
        } 
    

    The retains / releases are done for you. You haven’t said what sort of crash you are getting, but it seems like you are using ARC sample code in an MRC project.

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

Sidebar

Related Questions

I encounter error like this in my sql in running my program, How can
After I run the code in matlab, I encounter this error and unsure how
I run the TTCatalog application from the Three20 library and encountered this error when
I'm trying to call Dispatcher.PushFrame() from several different thread but encounter an error: Must
I'am very new to google-apps-script. I encounter this error TypeError: Cannot find function getValue
I am trying to run the program from http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf61c8a-7ff4.html I am using Adbobe builder
i encounter an error like Error 1 fatal error LNK1107: invalid or corrupt file:
I'm encounter a strange error and I don't know how to fix it. I'm
I encountered this error: Cannot implicitly convert type System.Web.UI.WebControls.LoginView to Login The error occured
I encountered this error: The type or namespace name 'WebControls' could not be found

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.