-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Conversation
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 Done. Thanks for review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@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. |
That should fix it. |
Looks good, thanks! |
* 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>
Goals ⚽
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 callstopListening
to set the context of callback nil.