Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If we call an invalidate whereas we've not called a schedule method, a crash emerges #20

Open
kos9kus opened this issue Feb 3, 2016 · 3 comments

Comments

@kos9kus
Copy link

kos9kus commented Feb 3, 2016

I init a new timer and before timer will schedule in some time within an execution, I call invalidate method prior to schedule, and see an error into following scope.

if (!OSAtomicTestAndSetBarrier(7, &_timerFlags.timerIsInvalidated))
    {
        dispatch_source_t timer = self.timer;
        dispatch_async(self.privateSerialQueue, ^{
            dispatch_source_cancel(timer);
            ms_release_gcd_object(timer);  // The error occurred !!! 
        });
    }

I think we need to check a reference counter of *_self.timer *_or remove ms_release_gcd_object(object) dispatch_release(object) when we work in ARC.

this is a note from Spec:
IMPORTANT
If your app is built with a deployment target of OS X v10.8 and later or iOS v6.0 and later, dispatch queues are typically managed by ARC, so you do not need to retain or release the dispatch queues.

@JaviSoto
Copy link
Contributor

JaviSoto commented Feb 3, 2016

That's what ms_release_gcd_object does: it doesn't call release if it doesn't have to, so that part of the code is correct.

Could you share a piece of code that reproduces the crash (a failing test case would be idea), and a full stack trace of the crash?

Thanks!

@kos9kus
Copy link
Author

kos9kus commented Feb 3, 2016

This is a simple test case

MSWeakTimer* heartBeatTimer = [ [MSWeakTimer alloc] initWithTimeInterval:pingPongTimeOut target:self selector:@selector(sendPing) userInfo:nil repeats:NO dispatchQueue:dispatch_get_main_queue() ];
[heartBeatTimer invalidate];

[system waitForTimeInterval:3];

screen shot 2016-02-03 at 20 09 09

@kos9kus kos9kus changed the title If we call a invalidate whereas we've not called a schedule method, a crash emerges If we call an invalidate whereas we've not called a schedule method, a crash emerges Feb 3, 2016
@kos9kus
Copy link
Author

kos9kus commented Feb 4, 2016

Did you get that ?
I repeat that, my case is I initialize a timer then inside my class there are exist 2 callbacks, success and error, If i get error callback, there will be invalidating timer, if i get success callback there will be scheduling timer. An error occurs when we try to invalidate a timer that wasn't scheduled.
Please give me some feedback or tips! Perhaps I should do some check whether timer was scheduled or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants