Skip to content

fix(apple): Fix memory leak in pathUpdateHandler#7890

Merged
jamilbk merged 3 commits intomainfrom
fix/prevent-retaining-self-in-pathUpdateHandler
Jan 28, 2025
Merged

fix(apple): Fix memory leak in pathUpdateHandler#7890
jamilbk merged 3 commits intomainfrom
fix/prevent-retaining-self-in-pathUpdateHandler

Conversation

@jamilbk
Copy link
Member

@jamilbk jamilbk commented Jan 28, 2025

In the didReceivePathUpdate private function, we capture an implicit hard reference to self because we access the Adapter instance properties. This function is called in the workQueue by the NWPathMonitor API and as such, we should weakly capture self throughout to prevent a retain cycle.

To fix this, we use a lazy var for the pathUpdateHandler closure, capturing [weak self] within it to use throughout the remainder of the callback.

@vercel
Copy link

vercel bot commented Jan 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 28, 2025 1:59am

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of this is just moving the didReceivePathUpdate function body to the closure directly.

@jamilbk jamilbk changed the title fix(apple): Prevent strong reference to self in pathUpdateHandler fix(apple): Fix memory leak in pathUpdateHandler Jan 28, 2025
@jamilbk jamilbk enabled auto-merge January 28, 2025 01:58
@jamilbk jamilbk added this pull request to the merge queue Jan 28, 2025
Merged via the queue into main with commit daf1b06 Jan 28, 2025
112 checks passed
@jamilbk jamilbk deleted the fix/prevent-retaining-self-in-pathUpdateHandler branch January 28, 2025 02:30
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