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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:47:14+00:00 2026-06-03T06:47:14+00:00

In my app I have a UIViewController subclass (VC for short) that I only

  • 0

In my app I have a UIViewController subclass (VC for short) that I only use in one place in the entire app. In that place, I have been creating and pushing it like this:

MyViewController* VC = [MyViewController new];
[self.navigationController pushViewController:VC animated:YES];
[VC release];

but I was thinking that since this is the only place I am using a view controller of this type, I could do something like this so the settings used won’t be reset each time the view controller is pushed onto the stack:

static MapsToSendPicker* VC = nil; 
if(!VC) {
    VC = [MapsToSendPicker new];
}

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

The problem with that code is that in VC’s dealloc method, I release all of my instance variables and set them to nil, and finally I call [super dealloc]. This deallocates the static view controller, but the test if(!VC) isn’t evaluated to true after (this would defeat the purpose of the whole idea if it were; then I’d have to recreate the view controller each time anyway).

My solution is overriding the dealloc method in MyViewController and not calling [super dealloc] at the end. This works, but the compiler raises a warning. How can I get rid of that warning while maintaining the functionality I gain with this design? Thanks!

Edit:

After a quick Google search, I have found this solution:

- (void)dealloc {
    if(NO) {
        [super dealloc];
    }
}

but I would like something a little bit… cleaner. Any thoughts?

  • 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-06-03T06:47:15+00:00Added an answer on June 3, 2026 at 6:47 am

    Remove the [VC release]; line and add [super dealloc] back. Everything will work properly and dealloc will never get called. Generally you should consider using NSUserDefaults in order to restore the VC properties instead of keeping the controller in memory all the time.

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

Sidebar

Related Questions

I have an app that have several views. In one view I would like
I have an app where I subclass UIViewController and add some characteristics to it,
I have a custom UIView subclass without a corresponding UIViewController. I use this class
in app i have custom tableview(UITableView *tableView) which subclass of uiviewcontroller & in tableview
In my app i have one UIViewController and there are many UIView which i
I have a UIViewController inside of a navigation based app. I'd like the view
I have a UIViewController subclass that used to have an associated nib file. I've
I have a little app that have by default youtube as homepage. You can
I have app in which i have recorded sound files i want that i
I have a very simple subclass of UIViewController : @interface RoastChickenViewController : UIViewController {

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.