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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:35:11+00:00 2026-05-20T10:35:11+00:00

I have a weird problem invalidating NSTimer. As long as the user is on

  • 0

I have a weird problem invalidating NSTimer. As long as the user is on a particular screen, I need to constantly update it. I’m using NSTimer to accomplish it. I wrote the below piece of code in viewDidLoad method.

- (void)viewDidLoad {
self.pollServerForUpdates = [NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(fetchNewDataFromServer:)
userInfo:nil
repeats:YES];
}

Problem is when I try to invalidate the timer. As I want the app to stop polling the server when the user leaves the screen, I put the timer invalidation code in viewWillDisappear method.

-(void) viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:YES];
//NSLog(@"%d",[self.view retainCount]);
[self.pollServerForUpdates invalidate];
self.pollServerForUpdates = nil;
}

I use a navigation controller to go back and forth between my main view and the polling view. The app crashes if I move between my main view and polling view real fast. I enabled the NSZombie to see whats happening and this is what I get

 *** -[CALayer retainCount]: message sent to deallocated instance 0x1c3be0

If I remove the timer invalidation my app works fine. But I want to stop the polling (timer) as soon as the user leaves the screen.

I believe this is happening because the timer is called a split second before the view is released, how do I avoid it? Do I need to change my design? Any help will be appreciated.

p.s: I can’t use push notifications on this screen.

  • 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-20T10:35:11+00:00Added an answer on May 20, 2026 at 10:35 am

    It may be that the bug is somewhere else, with some other class that is using your view without holding a reference to it. If you don’t invalidate your timer than it will have a reference to your view forever, potentially extending its lifespan and masking memory management bugs elsewhere in your code.

    Try breaking on exceptions, and see where the call to the zombie is coming from.

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

Sidebar

Related Questions

I have a weird problem, I am using print_r($obj) in Joomla YOOtheme ZOO extension
I have a weird problem. Using the mail() function and a local Postfix on
I have a weird problem with defining a mpi_type_contiguous and using mpi_gatherv later on.
I have a weird problem in asp.NET when calculating how many hours we need
I have weird problem. I'm using Eclipse for writing J2EE (java, jsf, javascript) application
I have a weird problem, I need to parse a date string that looks
I have a weird problem, I want to add a global query using context
I have a weird problem when using Seated Mode in the Xna Example of
I have some weird problem while uploading a file with a Cyrillic name using
I have a weird problem, I think. If I use a particular icon in

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.