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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:17:36+00:00 2026-05-17T22:17:36+00:00

I have the following simple piece of code: NSMutableArray *array = [[NSMutableArray alloc] init];

  • 0

I have the following simple piece of code:

NSMutableArray *array = [[NSMutableArray alloc] init];

    NSObject *o = [[NSObject alloc] init];
    NSObject *o1 = [[NSObject alloc] init];
    NSObject *o2 = [[NSObject alloc] init];

    [array addObject:o];
    [array addObject:o1];
    [array addObject:o2];
    NSLog(@"-------");
    NSLog(@"%d, %d, %d, %d\n", [o retainCount], [o1 retainCount], [o2
                                                                   retainCount], [array retainCount]);
    [array release];
    NSLog(@"%d, %d, %d, %d\n", [o retainCount], [o1 retainCount], [o2
                                                                   retainCount], [array retainCount]);
    [o release];
    [o1 release];
    [o2 release];
    NSLog(@"-------");
    NSLog(@"%d, %d, %d, %d\n", [o retainCount], [o1 retainCount], [o2
                                                                   retainCount], [array retainCount]);

as an output I’m getting:

[Session started at 2010-10-27 18:00:59 +0200.]
2010-10-27 18:01:02.186 Questions[22463:207] -------
2010-10-27 18:01:02.187 Questions[22463:207] 2, 2, 2, 1
2010-10-27 18:01:02.188 Questions[22463:207] 1, 1, 1, 1
2010-10-27 18:01:02.188 Questions[22463:207] -------

and the program crushes with EXC_BAD_ACCESS.

my question is following:
I understand that after calling [array release] the array object does not exist anymore, right? and the same is for calling release for the other objects, yes? If so, why I don’t get EXC_BAD_ACCESS after calling [array retainCount]? why it returns any value? and why calling retainCount on the other objects causes EXC_BAD_ACCESS?

Thanks for your help!

  • 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-17T22:17:37+00:00Added an answer on May 17, 2026 at 10:17 pm

    Well, as you correctly guessed you can’t send messages to objects that have already been released. The behavior if you do so is unspecified, so EXC_BAD_ACCESS might be raised, but it need not be.

    If you want to get retainCount from objets you already released, you should check out NSZombieEnabled(http://www.cocoadev.com/index.pl?NSZombieEnabled), which will cause objects to be released but not dealloc’ed.

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

Sidebar

Related Questions

I have the following simple code, where I double click a div (with class
I have the following simple Python code that makes a simple post request to
I have the following simple page: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
I am using C# 3.0. Following the standard event pattern I have: public event
I'm not the first to have these issues, and will list some reference posts
I have an ASP.NET application that relies on the Random class to generate a
A seriously flawed and retarded piece of software which goes by the name of
I have a SQL query I'm having trouble creating using NHibernate Criteria: SELECT ID,
I'm trying to format some text in NSTextView to be placed in a single
I'm having trouble selecting the text inside a span element that resides in another

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.