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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:40:25+00:00 2026-05-28T20:40:25+00:00

I have following code NSArray *myArray = [[NSArray alloc] initWithObjects:@1,@2,nil]; NSMutableDictionary *dic0 = [[NSMutableDictionary

  • 0

I have following code

NSArray *myArray = [[NSArray alloc] initWithObjects:@"1",@"2",nil];
NSMutableDictionary *dic0 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"parag", @"name", myArray, @"arraye",nil];
NSMutableDictionary *dic1 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"parag1", @"name", myArray, @"arrayr",nil];
NSMutableDictionary *dic2 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"parag2", @"name", myArray, @"arrayq",nil];
NSMutableDictionary *dic3 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"parag2", @"name", myArray, @"arrayqe",nil];
NSArray *array12424 = [[NSArray alloc] initWithObjects:dic0, dic1, dic2, dic3];

NSLog(@"array12424 %d", [array12424 retainCount]);
NSLog(@"array12424 %@", array12424);
int j = [myArray retainCount];
for(int i=0;i<j; ++i)
{
    [myArray release];
        NSLog(@"%d", i);
    NSLog(@"myArray %@", myArray);
}

NSLog(@"array12424 %@", array12424);  

After releasing myArray,i expected crash; why arraye and other array key are pointing to array12424?

//output  

  2012-02-02 12:33:58.454 212121212[6924:a0f] array12424 1
    2012-02-02 12:33:58.459 212121212[6924:a0f] array12424 (
            {
            arraye =         (
                1,
                2
            );
            name = parag;
        },
            {
            arrayr =         (
                1,
                2
            );
            name = parag1;
        },
            {
            arrayq =         (
                1,
                2
            );
            name = parag2;
        },
            {
            arrayqe =         (
                1,
                2
            );
            name = parag2;
        }
    )
    2012-02-02 12:33:58.459 212121212[6924:a0f] 0
    2012-02-02 12:33:58.460 212121212[6924:a0f] myArray (
        1,
        2
    )
    2012-02-02 12:33:58.460 212121212[6924:a0f] 1
    2012-02-02 12:33:58.460 212121212[6924:a0f] myArray (
        1,
        2
    )
    2012-02-02 12:33:58.461 212121212[6924:a0f] 2
    2012-02-02 12:33:58.462 212121212[6924:a0f] myArray (
        1,
        2
    )
    2012-02-02 12:33:58.463 212121212[6924:a0f] 3
    2012-02-02 12:33:58.463 212121212[6924:a0f] myArray (
        1,
        2
    )
    2012-02-02 12:33:58.464 212121212[6924:a0f] 4
    2012-02-02 12:33:58.466 212121212[6924:a0f] myArray myArray 
    2012-02-02 12:33:58.466 212121212[6924:a0f] array12424 (
            {
            arraye = "array12424 ";
            name = parag;
        },
            {
            arrayr = "array12424 ";
            name = parag1;
        },
            {
            arrayq = "array12424 ";
            name = parag2;
        },
            {
            arrayqe = "array12424 ";
            name = parag2;
        }
    )

I am using MAC osx 10.6 base SDK.

  • 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-28T20:40:27+00:00Added an answer on May 28, 2026 at 8:40 pm

    0) Do not use retainCount.

    1) Cocoa Collections retain their contents, then release them when they are removed, or when the collection is destroyed. Furthermore there’s no documentation which explicitly states the APIs you call through will not autorelease their arguments.

    2) You don’t initialize your array correctly — it must be nil terminated: NSArray *array12424 = [[NSArray alloc] initWithObjects:dic0, dic1, dic2, dic3];

    3) Simply put, it does not matter — It’s Undefined Behavior. The result cannot be predicted (unless it involves raptors). It crashes in other OS versions. It crashes as you’d expect with GuardMalloc enabled. It crashes shortly afterwards (provided you’re lucky).

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

Sidebar

Related Questions

I have the following code: NSString *indexText = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if (indexText==nil)
I have the following code: NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; NSString *temp;
I have the following code: NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:myarray1, @array1, myarray2, @array2
i have the following code... DistanceInformation *distanceInformation=[[DistanceInformation alloc]init]; NSArray *latLongArray=[distanceInformation calculateDistance]; [distanceInformation release]; NSLog(@lat
I have following code class User attr_accessor :name end u = User.new u.name =
I have the following code: self.shareButton=[[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 35, 35)]; [shareButton setBackgroundColor:[UIColor blueColor]];
I have the following code: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory =
I have the following code showing location objects from an NSArray in a table,
i have the following code in my application: NSArray *lstAttributes = [conditionAttribute componentsSeparatedByString:cstrSystemUIConfigurationAttributeConditionSeparator], *lstValues
I have the following code in a method of my app: NSArray *array =

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.