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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:58:47+00:00 2026-05-18T08:58:47+00:00

I’m diving into iOS development and I’m building a navigation based app that wasn’t

  • 0

I’m diving into iOS development and I’m building a navigation based app that wasn’t fully releasing one of the views that was being pushed onto the nav stack. This is problematic because the view controller is never being deallocated, so the memory it uses just builds up every time the view controller is pushed on to the stack. So after investigating the issue, I found the retain counts for the view controller were really strange. The view controller in question is pushed on to the stack once a countdown timer reaches zero.

Here’s the code that creates the view controller in the timer callback, displays its retain count, and pushes it onto the nav stack…

-(void)updateCountDownTimer   //Defined in MyViewController_A class
{
    [self setTimeRemaining:([self timeRemaining] - 1)];

    [[self countDownLabel] setAlpha:1];
    [[self countDownLabel] setText:[NSString stringWithFormat:@"%d", [self timeRemaining]]];

    //Fade out the current time
    [UIView beginAnimations:@"FadeAnimation" context:nil];
    [UIView setAnimationDuration:1];
    [[self countDownLabel] setAlpha:0];
    [UIView commitAnimations];  

    if ([self timeRemaining] == 0) 
    {       
        MyViewController_B *myvc_b = [[MyViewController_B alloc] initWithNibName:@"MyView_B_iPhone" bundle:nil];
        [[self navigationController] pushViewController:myvc_b animated:YES];
        NSLog(@"updateCountDownTimer: %d", [myvc_b retainCount]);
        [myvc_b release];

        [[self countDownTimer] invalidate];
        [[self countDownLabel] setHidden:YES];
    }
}

and here’s the code that pops the view controller off the nav stack once the pause button is pressed…

- (void)pauseButtonPressed:(id)sender
{
    //Stop the timer
    [puzzleTimer invalidate];

    NSLog(@"pauseButtonPressed before pop: %d", [self retainCount]);

    //return to the previous view
    [[self navigationController] popViewControllerAnimated:YES];

    NSLog(@"pauseButtonPressed after pop: %d", [self retainCount]);
}

and here’s the console output that shows really strange retain counts throughout the process…

2010-12-02 17:50:38.062 MyApp[821:307] updateCountDownTimer: 5
2010-12-02 17:50:40.453 MyApp[821:307] pauseButtonPressed before pop: 2
2010-12-02 17:50:40.462 MyApp[821:307] pauseButtonPressed after pop: 4

I’m new to iOS development, but the code seems pretty straightforward to me, so I don’t know what I’m missing.

Thanks so much in advance for your wisdom!

UPDATE: It looks like the Leaks instrument is reporting a leak on the line of code that pushes the previous view controller onto the stack (that is, the view controller responsible for pushing the view controller in question). The code is once again very straightforward, so I don’t know why it’s reporting a leak…

MyViewController_A *myvc_a = [[MyViewController_A alloc] initWithNibName:@"MyView_A_iPhone" bundle:nil];

[[self navigationController] pushViewController:myvc_a animated:YES]; //<--Leak being reported here

[myvc_a release];

*UPDATE:*Found the problem, it was just as everyone was saying and the same problem as was shown in the link posted in the comments below, I had live objects still referencing my view controller, which prevented it from deallocating. In my case, I had two timers that were targeting my view controller and those timers weren’t being invalidated before I popped the view off the stack, which meant there were two live objects still referencing the view controller. Here’s a snippet I found in the Apple docs which uncovered the problem…

Perhaps more importantly, a timer also
maintains a strong reference to its
target. This means that as long as a
timer remains valid (and you otherwise
properly abide by memory management
rules), its target will not be
deallocated.

Anyhow, thanks again to everyone who helped!

  • 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-18T08:58:47+00:00Added an answer on May 18, 2026 at 8:58 am

    There is nothing wrong with your code as far as memory management is concerned.

    You should not rely on retain counts to check if your objects are being released properly as the system will also be retaining what it needs and releasing when appropriate. For instance when you add your view controller to the stack it gets retained by the nav controller along with its subviews and when it’s popped out it gets send a release message which propagates all of its subviews.

    The general rule is if you alloc, retain or copy an object, it is your responsibility to release it. Everything else is dealt with by the system and will be flushed with the auto release pool.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.