Skip to content

Conversation

@Hydra2050
Copy link

When timerFired invoking , if self is setting to nil when self.selector is called, self will be a zombie.

// We're not worried about this warning because the selector we're calling doesn't return a +1 object.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.target performSelector:self.selector withObject:self];
#pragma clang diagnostic pop

if (!self.repeats)
{
    [self invalidate];
}

So, make a strong self object , make the retaincount +1, make sure self will not dealloc within this scope.

MSWeakTimer *strongSelf = self;
// We're not worried about this warning because the selector we're calling doesn't return a +1 object.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.target performSelector:self.selector withObject:self];
#pragma clang diagnostic pop

if (!strongSelf.repeats)
{
    [strongSelf invalidate];
}

@JaviSoto
Copy link
Contributor

Sorry for the super late response, I never saw this until now!

Hmmm do you have a test that shows that bug? And that it proves that this fixes it? That would be useful.
AFAIK if self is deallocating, increasing its retain count by acquiring a strong reference would also crash...

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

Successfully merging this pull request may close these issues.

2 participants