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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:29:56+00:00 2026-05-16T06:29:56+00:00

I have been wondering which is the best way to load a navigation view.

  • 0

I have been wondering which is the best way to load a navigation view. I have found that there are 3 ways I can do it without having major errors

What I was wondering is which one is best for memory and as a recommended practice ??

1)
no declaration in .h file (the code below IS NOT writen in the .h file)

@interface companyViewController : UIViewController {  
    EmployeeViewController *employeeDetailViewController;  
}  
@property (nonatomic, retain) EmployeeViewController *employeeDetailViewController;  

then no @syntesize in .m file, no release in dealloc and no nil in viewDidUnload and when I call the new view I do:

EmployeeViewController *employeeController = [[EmployeeViewController alloc]  
      initWithNibName:@"EmployeeViewController" bundle:nil];  

[self.navigationController pushViewController:employeeController animated:YES];  
[employeeController release];  

2)
I create it in the .h file (the code below IS written in the .h file)

@interface companyViewController : UIViewController {  
    EmployeeViewController *employeeDetailViewController;  
}  
@property (nonatomic, retain) EmployeeViewController *employeeDetailViewController;  

then I @syntesize in .m file, with a release in dealloc and a nil in viewDidUnload and when I call the new view I do:

EmployeeViewController *employeeController = [[EmployeeViewController alloc]  
      initWithNibName:@"EmployeeViewController" bundle:nil];  

employeeDetailViewController = employeeController;  

[self.navigationController pushViewController:employeeController animated:YES];  
[employeeController release];  

3)
I do like 2 but I call the new view like this

employeeDetailViewController = [[EmployeeViewController alloc]  
      initWithNibName:@"EmployeeViewController" bundle:nil];  

[self.navigationController pushViewController:employeeController animated:YES];  

I feel like #3 is wrong because from what I understand in the memory management, I allocate it once in the @property (nonatmoic, retain) and I also retain it when I alloc it when I decide to call it. This will make the view have a retain count of 1 and lead to leaks.

To make sure I do not create an excessive amount of new views and get EXC_BAD_ACCESS or memory leaks, which one should be best ?

Thanks for the 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-16T06:29:57+00:00Added an answer on May 16, 2026 at 6:29 am

    In none of these examples are you actually using the property you declare. I’ll go through them in turn.

    1. You created a property called employeeDetailViewController, but you never synthesize it or store anything in it. Your view controller is only ever stored in a local variable before passing it off to the navigation controller.

    2. You create an instance variable called employeeDetailViewController, and a property also called employeeDetailViewController. However, you never store anything in the property, you only access the instance variable directly. Since you don’t retain the view controller (it doesn’t happen automatically when you use instance variables), you’ve got a situation where you might over-release.

    3. This one will actually crash. You told it to pushViewController:employeeController without having defined employeeController.

    So, let’s consider what’s right. There are two issues here: firstly, how to use properties, and secondly, whether you need an instance variable/property to refer to the view controller at all.

    Considering properties:

    To access a property, you use self.propertyName. If you just use propertyName directly, you’re writing directly into the instance variable, and the memory management stuff (like automatically retaining stuff that’s put in the property) is completely bypassed. Generally, you should only ever do that in your init or dealloc method: everywhere else you should access the property properly by self.propertyName.

    Do you need an instance variable/property for the view controller?

    I would say you don’t actually need an instance variable or property for the view controller you’re pushing. Once it’s been handed off to the navigation controller, in general you won’t need to access it again. My version of your code would be:

    aViewController = [[EmployeeViewController alloc]  
          initWithNibName:@"EmployeeViewController" bundle:nil];  
    
    [self.navigationController pushViewController:aViewController animated:YES];
    

    Unless you’re wanting to refer to that particular view controller from elsewhere in your code, this is all you need. Nothing in the header, no property anywhere.

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

Sidebar

Related Questions

I have been wondering about the reload() function in python, which seems like it
Lately i have been wondering if there is a performance difference between repeating the
Im wondering if someone can help me understand the best way for me to
I have been doing some OO Perl programming and I was wondering: which is
I have been wondering about how people manage their strings if they are likely
I have been wondering about the following lines of code [self performSelector:@selector(myMethod) withObject:self afterDelay:1.0];
I have been wondering and couldn't find a clear answer on this subject. Imagine
I have been wondering about the performance of regular expression implementations lately, and have
Something I have been wondering about properties for a while. When you are using
I've been hacking around with Ruby a little and I have been wondering if

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.