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 following piece of code NSMutableArray *mutArray = [[NSMutableArray alloc] init]; [mutArray addObject:
I have the following piece of code, executing a pretty simple MySQL query: $netnestquery
I have a simple application with the following code: FileInfo[] files = (new DirectoryInfo(initialDirectory)).GetFiles();
I have a very simple piece of code that I used in previous versions
I have the following code (correct for my simple tests) for a linked list
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 piece of code to calculate how far back in the
We have the following simple Stored Procedure that runs as an overnight SQL server
I have the following simple button with an image as the template. The problem

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.