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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:15:02+00:00 2026-05-25T22:15:02+00:00

Sorry to ask this question, but it’s now day 3 I try to solve

  • 0

Sorry to ask this question, but it’s now day 3 I try to solve this problem and have no progress so far.

The problem is this: during a game there is a pause between the user answered a question and the next question. Also in several other cases there are such pauses in gameplay. For this I use one NSTimer.

In .h I have:

@property(nonatomic,retain) NSTimer *scheduleTimer;

and in the .m

@synthesize scheduleTimer;

scheduleTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target: self selector: @selector(playFeedbackSound) userInfo: nil repeats: NO];

now this works just fine. But when the user exits the ViewController I need to invalidate the timer. Otherwise the timer will fire and then crash the app or pops up stuff that does not belong in the other view etc.

Therefore I write:

- (void)viewWillDisappear:(BOOL)animated {
    [scheduleTimer invalidate];   
}

now this does the job if the timer is actually set. But if there is no such timer scheduled, the app just crashes.

I tried probably everything there is, including @try (which crashes the app too, Zombie says “* -[CFRunLoopTimer invalidate]: message sent to deallocated instance 0x567640″). Since the timer gets released after it is done, a [scheduleTimer isValid] will just crash the app as well.

Now I’m already pretty desperate, and as a last resort I’m thinking of replacing the timer with UIView animateWithDuration that does nothing visible.

However, I think this should be a pretty standard situation. I just don’t know why I can’t find an answer to this very obvious task. Can you help? Thank you

  • 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-25T22:15:02+00:00Added an answer on May 25, 2026 at 10:15 pm

    I think the problem is that the NSTimer gets autoreleased before you invalidate it.

    So you should do:

    scheduleTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target: self selector: @selector(playFeedbackSound) userInfo: nil repeats: NO] retain];
    

    And you should also release the timer in viewWillDisappear:

    [scheduleTimer release];
    

    But an even better solution is probably to use the dot property syntax to care of retain/release:

    self.scheduleTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target: self selector: @selector(playFeedbackSound) userInfo: nil repeats: NO];
    

    And then:

    - (void)viewWillDisappear:(BOOL)animated {
        if (self.scheduleTimer != nil) {
            [self.scheduleTimer invalidate];
            self.scheduleTimer = nil;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry to ask this question again but I tried several solutions on stackoverflow and
(I am sorry, I wanted to ask this question on meta first, but it
Sorry, this's my first time to ask a question here. So, I don't have
I'm really sorry to have to ask this, but I clearly don't understand something
I am sorry to ask this trivial question but I could not find a
I am using cakePHP 1.26. I am sorry to ask this question, but I
I am sorry to ask this question when it has already been asked but
I'm sad to have to ask this question, but I'm not even sure of
I am really sorry to ask this silly question. I have been onto this
I'm sorry if this question is a dumb one, but I must ask. 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.