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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:57:50+00:00 2026-06-15T10:57:50+00:00

As part of my app startup, I cycle through several view controllers. Everything works,

  • 0

As part of my app startup, I cycle through several view controllers. Everything works, but the view controllers are not released. ( viewDidUnload and dealloc are never called ). Prior to each state change, I dismiss any presented view controllers. They are dismissed, and viewWillDisappear is called for each view controller:

- (void)stateChange:(NSString *)state {

// Dismiss any exiting modals/popups
[self dismissPopup];
[self dismissModalViewControllerAnimated: NO];        

if([state isEqualToString:@"StateBoot"]) {

    CLRemotePrimaryBootViewController * viewControllerBoot = [[CLRemotePrimaryBootViewController alloc]initWithNibName: @"CLRemoteBootView" bundle:nil];
    [self presentModalViewController:viewControllerBoot animated:NO];   
    [viewControllerBoot release];
}

else if([state isEqualToString:@"StateLogin"]) {

    CLRemotePrimaryAuthViewController *viewControllerAuth = [[CLRemotePrimaryAuthViewController alloc]initWithNibName: @"CLRemoteAuthView" bundle:nil];
    [self presentModalViewController:viewControllerAuth animated:NO]; 
    [viewControllerAuth release];
}

else if([state isEqualToString:@"StateMain"]) {

    [self setSelectedIndex:0];
}

else if([state isEqualToString:@"StateStop"]) {

    // TBD
}

}

After dismissal, self.presentedViewController is in fact nil. Any ideas on how I can coerce iOS to release these unused view controllers?

EDIT –

SOLVED! Hope this post helps others – I was baffled. It turns out that my modal view controllers were derived from a base class that set up observers (NSNotificationCenter) in the init method. These observers must be removed before the observing view controller can be released. In my case this was made more difficult because the observers were blocks instead of selectors. When adding these observers, and id is returned for each one – and so I had to keep track of these in an NSMutableArray and add a method to release the observers in my base class:

+ (void) safeUnsubscribe:(id)object {

if ( object != nil ) {

    if ( [object isKindOfClass:[CLRemotePrimaryBaseViewController class]]) {

        CLRemotePrimaryBaseViewController* viewController = (CLRemotePrimaryBaseViewController*)object;
        [viewController unsubscribe];
    }        
}

}
`

`- (void)handle:(NSString *)name usingBlock:(CLObjBlock)block {

id observer = [[NSNotificationCenter defaultCenter] addObserverForName:name object:nil queue:nil usingBlock:^(NSNotification * notification){ block([notification object]); }];
[self.observers addObject:observer];    

}`

// Must call before dealloc or listener will never be released!

`- (void)unsubscribe {

for ( id observer in self.observers ) {

    [[NSNotificationCenter defaultCenter] removeObserver:observer];
}

[self.observers removeAllObjects];

[[NSNotificationCenter defaultCenter] removeObserver:self];

}

  • 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-15T10:57:51+00:00Added an answer on June 15, 2026 at 10:57 am

    SOLVED! Hope this post helps others – I was baffled. It turns out that my modal view controllers were derived from a base class that set up observers (NSNotificationCenter) in the init method. These observers must be removed before the observing view controller can be released. In my case this was made more difficult because the observers were blocks instead of selectors. When adding these observers, and id is returned for each one – and so I had to keep track of these in an NSMutableArray and add a method to release the observers in my base class:

    + (void) safeUnsubscribe:(id)object {
    
    if ( object != nil ) {
        if ( [object isKindOfClass:[CLRemotePrimaryBaseViewController class]]) {
    
            CLRemotePrimaryBaseViewController* viewController = (CLRemotePrimaryBaseViewController*)object;
            [viewController unsubscribe];
        }        
    }
    
    } 
    
    
    
    - (void)handle:(NSString *)name usingBlock:(CLObjBlock)block {
    
    id observer = [[NSNotificationCenter defaultCenter] addObserverForName:name object:nil queue:nil usingBlock:^(NSNotification * notification){ block([notification object]); }];
    [self.observers addObject:observer];    
    
    }
    
    
    // Must call before dealloc or listener will never be released!
    
    - (void)unsubscribe {
    
    for ( id observer in self.observers ) {
    
        [[NSNotificationCenter defaultCenter] removeObserver:observer];
    }
    
    [self.observers removeAllObjects];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As part of my App's startup procedure, it checks data integrity, and if it
I have a mapkit / view and it works fine - but I scroll
I've been developing my first iPhone app part-time and would like to start using
Part of my app caches web pages for offline viewing. To do that, I
Part of an app I am working on includes a log file viewer, with
This part of an app that I am working on, I have the following
I have a part of my app that takes a screenshot of a certain
I have written an app and part of it is uses a URL parser
I have built part of my app and wanted to test it out. All
I'm making one part in my app where if you push the button then

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.