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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:41:03+00:00 2026-05-30T15:41:03+00:00

Ok, here is the error I am getting: -[CFRunLoopTimer invalidate]: message sent to deallocated

  • 0

Ok, here is the error I am getting:

    -[CFRunLoopTimer invalidate]: message sent to deallocated instance 0x109b05a0 (gdb)

Here is the code causing the crash:

    if (waitingOpponentTimer) {
      [waitingOpponentTimer invalidate]; //<-- Crash/error occurs here
      waitingOpponentTimer = nil;
    }

And elsewhere:

    NSTimer* waitingOpponentTimer;

And also:

    waitingOpponentTimer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(waitingOpponentTimeOut)userInfo:nil repeats:NO];

There is NO other occurence of waitingOpponentTimer anywhere, only the ones I have shown above. waitingOpponentTimeOut action just sets a few variables and does nothing to timers or to waitingOpponentTimer.

I have tried all the following IF statements to prevent the invalidate statement from being reached:

    if (waitingOpponentTimer) {
    if ([waitingOpponentTimer retainCount] > 0) {
    if (waitingOpponentTimer.isValid) {
    if (waitingOpponentTimer != nil) {

But in all cases, it still gets thru the IF statement and then causes the crash with the invalidate statement.

So my question is, why/how is invalidate causing an error when the object isValid and is not nil and it’s retainCount is greater than zero?

Is there another way to check this to prevent invalidate from being reached?

I am a complete noob to iphone programming and have spent several hours googling to try and figure this out but cannot figure out what I am doing wrong. Any help and suggestions appreciated!

EDIT:
Just to clarify, I am using this to manually stop the timer before it runs. I understand that if it runs out, it invalidates itself, which is why I am using the IF statement to check if it has already been invalidated (but it is not working). So I think the timer has already invalidated itself when this crash happens, but how do I check if it is already invalidated?

EDIT:
Ok I marked the correct answer below. I do not know if there is actually a reason why the code gets by the IF statements when the timer was not retained and has already invalidated itself, but the answer is to always use RETAIN if you are going to use the timer in an IF statement.

Here is related info: Is there any reason to retain a scheduled NSTimer if you don't need to invalidate it?

  • 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-30T15:41:04+00:00Added an answer on May 30, 2026 at 3:41 pm

    Do you use ARC?

    waitingOpponentTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(waitingOpponentTimeOut)userInfo:nil repeats:NO] retain];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting syntax error in firebug here is the code : $('#moderator-attention').live('toogle', function(){ function
I keep getting this error while trying to modify some tables. Here's my code:
Here is the piece of code that I am getting error, SDL_Rect's definition is
I'm trying to compile some code. Here is the error I'm getting: error while
i am developing parser using bison...in my grammar i am getting this error Here
Please refer my previous post here . I did changes accordingly but getting error.
I'm getting this error: -[NSCFArray insertObject:atIndex:]: attempt to insert nil Here is the .m
I am getting an error in an ajax call from jQuery. Here is my
I'm getting crazy with a small problem here, I keep getting an error and
Ok... changing the question here... I'm getting an error when I try this: SELECT

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.