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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:10:46+00:00 2026-05-23T17:10:46+00:00

is it OK to retain a variable passed by value in objective-c? That is

  • 0

is it OK to retain a variable passed by value in objective-c?

That is say:

  • I have controller 1 I have a variable that I pass to controller 2
  • it’s effectively passed by reference and I can use this when the use clicks on the controller 2 UINavigationController backbutton, in that the value will be modified in controller 1
  • in controller 2 I have setup a ivar per the code below

Question – So is it OK for this controller 2 variable to be set using “Retain”, and also have it “released” and set to nil in the “dealloc” method? that is it won’t affect the object for controller 1? What happens for example if controller 2 is deallocated and the “release” and “=nil” is hit, will this affect the object as it’s still used by controller 1.

Controller 2 Code extract

@interface SelectorController : UITableViewController {
    Config *_returnObject;
}
@property (nonatomic, retain) Config *returnObject;
@end


// implementation
@synthesize config;  
- (void)dealloc
{
    [config release];               config = nil;
    [super dealloc];
}
  • 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-23T17:10:46+00:00Added an answer on May 23, 2026 at 5:10 pm

    Retaining and releasing the variable in controller 2 is more than OK, it’s how you should do it. 🙂

    Setting the variable to nil in the controller 2, will only set the variable to nil, not the stuff the variable points to, so your object will still be there for the variable in controller 1 to work with.

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

Sidebar

Related Questions

I have an app (using retain/release, not GC) that maintains an NSArray instance variable,
let's say I have an instance variable MyObject* test; @property(nonatomic, retain) MyObject* test; .m
I want to get variable value from an objective-c class, using reflection. company.h looks
Normally i've been passing variable around in init methods, but I can't do that
Imagine I have a member variable @property(nonatomic,retain)NSArray *array; Now in my viewDidLoad I set
I set a variable as IBOutlet. and use @property(retain) @synthesize in my .h and
I'm editing variable length lists and use ViewData to pass around information for filling
A simple question regarding multhreading programming: I have an NSMutableArray instance variable that is
I have a variable lastPostsGrabbedCounter , an NSNumber , that is defined below. .h
i am trying to retain the value of a variable from a previous page.

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.