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

Fix memory leak in NetworkReachabilityManager. #3180

Merged
merged 4 commits into from
May 15, 2020

Conversation

dirtmelon
Copy link
Contributor

Goals ⚽

  • Fix a memory leak in NetworkReachabilityManager

Implementation Details 🚧

As passRetained(_:) described, it creates an unmanaged reference with an unbalanced retain.The instance passed as value will leak if nothing eventually balances the retain.
In this case, we don't need to perform a retain, if the NetworkReachabilityManager deinit, we will call stopListening to set the context of callback nil.

@jshier
Copy link
Contributor

jshier commented May 8, 2020

Thanks for the PR! Your're right, this is likely a bug. Would it be possible to demonstrate the cycle with a test? Say, create an optional manager, capture it weakly, start and stop it, then nil the reference and check the weak reference to see if it's still around?

@jshier jshier self-assigned this May 8, 2020
@dirtmelon
Copy link
Contributor Author

@jshier Done. Thanks for review :)

Copy link
Contributor

@jshier jshier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jshier
Copy link
Contributor

jshier commented May 15, 2020

@dirtmelon Looks like the added tests has an up to 10% failure rate, so there may be something else keeping the reference alive or internal async processes we need to wait for. I'm investigating, but I'd appreciate your attention too.

@jshier
Copy link
Contributor

jshier commented May 15, 2020

That should fix it.

@jshier
Copy link
Contributor

jshier commented May 15, 2020

Looks good, thanks!

@jshier jshier merged commit e217713 into Alamofire:master May 15, 2020
@jshier jshier modified the milestones: 5.X, 5.2.0 May 15, 2020
pull bot pushed a commit to scope-demo/Alamofire that referenced this pull request May 15, 2020
* Fix memory leak.

* Update deinitialization test for NetworkReachabilityManager.

rename

* Add assertion, clean up formatting.

* Make deinit tests more resilient.

Co-authored-by: Jon Shier <jon@jonshier.com>
@dirtmelon dirtmelon deleted the patch-1 branch May 17, 2020 10:26
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