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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:57:53+00:00 2026-05-20T04:57:53+00:00

I need some info about how to assign, retain objects. For example – if

  • 0

I need some info about how to assign, retain objects.

For example – if we have two viewcontrollers and needed to pass an array data from viewcontrlr 1 to viewContrl 2, how can we send the object from view 1 to view 2 and release it in view 1 and retain it in view 2.

A simple = operator is just assigning the address which again points to view 1 object. What is the best way so we can release obj in view 1 and retain a new object in view 2 when passed from view 1.

  • 1 1 Answer
  • 3 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-20T04:57:54+00:00Added an answer on May 20, 2026 at 4:57 am

    Create a NSMutableArray in your view controller 2 and declare a retain property for it.

    @interface VC2 : UIViewController
    {
       NSMutableArray *mutableArrayInVC2
    } 
    @property (nonatomic, retain) NSMutableArray *mutableArrayInVC2
    

    Then in your view controller one you can pass it with:

    viewController2Instance.mutableArrayInVC2 = mutableArrayInVC1
    

    And it’s safe to release it with:

    [mutableArrayInVC1 release];
    

    [EDIT TO ADDRESS YOUR COMMENT]

    When you declare a retain property for your mutableArrayInVC2 and pass mutableArrayInVC1 to it, “behind the scenes” you are accessing the variable via its setter method as per below:

    -(void)setMutableArrayInVC2:(NSMutableArray *)arrayValue
    {
        [arrayValue retain]; // This is your mutableArrayInVC1
        [mutableArrayInVC2 release]; // This is nil the first time you access it which is cool - we can send messages to nil in ObjC
        mutableArrayInVC2 = arrayValue; // So basically you end up doing and assignment but only after retaining the object so it is pointing to the same memory address BUT it is now 'owned' by your VC2 instance.
    }
    

    Hope it makes sense!
    Rog

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

Sidebar

Related Questions

I have a need to display some basic info about a facebook group on
I need to store various info about some movies, books, games, and maybe other
I need some help - I have tried setting setSpecificDate so that the array
I have a database efficiency question. Here is some info about my table: -table
I need to get one page (can be cURL, or filegetcontent), get some info
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I have two tables on different servers, and I'd like some help finding an
I need to get some info passed as a lambda expression to some methods.

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.