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

  • Home
  • SEARCH
  • 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 612213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:52:07+00:00 2026-05-13T17:52:07+00:00

I have code in my project as follows. I am adding view controllers’ view

  • 0

I have code in my project as follows. I am adding view controllers’ view to the each cell of table view.

An array, like these

NSMutableArray *arrTbl=[[NSMutableArray alloc] init];
NSMutableDictionary *dOne=[[NSMutableDictionary alloc] init];
myViewController *objVCtr=[[myViewController alloc] initWithNibName:@"myViewController" bundle:nil];
[dOne setValue:objVCtr forKey:@"cellVCtr"];

NSMutableDictionary *dTwo=[[NSMutableDictionary alloc] init];
myViewController *objVCtr1=[[myViewController alloc] initWithNibName:@"myViewController" bundle:nil];
[dOne setValue:objVCtr1 forKey:@"cellVCtr"];

NSMutableDictionary *dThree=[[NSMutableDictionary alloc] init];
myViewController *objVCtr2=[[myViewController alloc] initWithNibName:@"myViewController" bundle:nil];
[dOne setValue:objVCtr2 forKey:@"cellVCtr"];

[arrTbl addObjectsFromArray:[NSArray arrayWithObjects:dOne,dTwo,dThree,nil]];

Now, the question is, how to release this?

arrTbl is main array having dictionaries & dictionaries having ref of view controllers.

So, Should I write following statements after above statements?

[dOne release];
[dTwo release];
[dThree release];
[objVCtr release];
[objVCtr1 release];
[objVCtr2 release];

After writing above code, array can point to the view controllers or not?

To summarise, the questions are:

  • What does actually dictionary contain? (Is it retain count of View controllers or just reference of view controllers)
  • What does array actually contain? (Is it retain count of dictionaries or just reference of dictionaries?)
  • here I just want to have an array of view controllers & each view controllers with different values (for that I am adding dictionary to an array)
  • 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-13T17:52:08+00:00Added an answer on May 13, 2026 at 5:52 pm

    Dictionaries and arrays contain pointers to objects, but the internal implementation of these classes is not important. What you do need to pay attention to is the ownership of objects.

    Have a look at http://boredzo.org/cocoa-intro/, in particular the memory management section which states:

    • If you create an object with a method whose selector contains the
      word “alloc” or “new”, or with a
      function whose name contains the word
      “Create”, then you own it.
    • If you make a copy of an existing object using a method whose selector
      contains the word “copy”, or from a
      function whose name contains the word
      “Copy” (or obtain an object from such
      a function), then you own the copy.
    • Otherwise, you don’t own the object.
    • If you own an object, you are obliged to release it.

    In your case you are creating the objects using -alloc, so you own the objects and are responsible for them. So, yes, you do need to release them after adding them to the array.

    NSArray and NSDictionary retain their members, so once you’ve added an object to an array or dictionary you can safely release it, the object won’t be deallocated until the array itself removes the object or is deallocated itself.

    To make it easier for yourself, you can use the convenience constructors which return autoreleased objects:

    //note the autorelease when the view controllers are created
    MyViewController* viewController = [[[MyViewController alloc] initWithNibName:@"myViewController" bundle:nil] autorelease];
    NSDictionary *dOne = [NSDictionary dictionaryWithObject:viewController forKey:@"cellVCtr"];
    
    
    MyViewController *objVCtr1 = [[[MyViewController alloc] initWithNibName:@"myViewController" bundle:nil] autorelease];
    NSDictionary* dTwo = [NSDictionary dictionaryWithObject:objVCtr1 forKey:@"cellVCtr"];
    
    MyViewController *objVCtr2 = [[MyViewController alloc] initWithNibName:@"myViewController" bundle:nil];
    NSDictionary* dThree = [NSDictionary dictionaryWithObject:objVCtr2 forKey:@"cellVCtr"];
    
    NSArray* arrTbl = [NSArray arrayWithObjects:dOne, dTwo, dThree, nil];
    
    //do something with arrTbl
    //make sure you retain it if you want to hang on to it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer On IIS6 you can simply add validate="false" in the web.config… May 14, 2026 at 8:41 pm
  • Editorial Team
    Editorial Team added an answer Mostly it is table size. I am assuming here that… May 14, 2026 at 8:41 pm
  • Editorial Team
    Editorial Team added an answer You could use CSS and redefine the elements or use… May 14, 2026 at 8:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.