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

[ios] fix memory leak in WindowOverlay #16700

Merged
merged 1 commit into from
Aug 14, 2023

Conversation

jonathanpeppers
Copy link
Member

Context: #16346

This addresses the memory leak discovered by:

src/Core/src/WindowOverlay/WindowOverlay.iOS.cs(92,40): error MA0001: Event 'OnTouch' could cause memory leaks in an NSObject subclass. Remove the event or add the [UnconditionalSuppressMessage("Memory", "MA0001")] attribute with a justification as to why the event will not leak.

I could reproduce a leak by writing a custom test.

Solved the problem by:

  • Removed the PassthroughView.OnTouch event completely. We could just call WindowOverlay.OnTappedInternal() directly instead of going through an intermediate event.

  • WindowOverlay overlay is now a WeakReference<WindowOverlay>.

Context: dotnet#16346

This addresses the memory leak discovered by:

    src/Core/src/WindowOverlay/WindowOverlay.iOS.cs(92,40): error MA0001: Event 'OnTouch' could cause memory leaks in an NSObject subclass. Remove the event or add the [UnconditionalSuppressMessage("Memory", "MA0001")] attribute with a justification as to why the event will not leak.

I could reproduce a leak by writing a custom test.

Solved the problem by:

* Removed the `PassthroughView.OnTouch` event completely. We could just
  call `WindowOverlay.OnTappedInternal()` directly instead of going
  through an intermediate event.

* `WindowOverlay overlay` is now a `WeakReference<WindowOverlay>`.
@jonathanpeppers jonathanpeppers added platform/iOS 🍎 memory-leak 💦 Memory usage grows / objects live forever labels Aug 11, 2023
@jsuarezruiz
Copy link
Contributor

Waiting the build but looks nice so far.

@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 11, 2023 18:37
@jonathanpeppers jonathanpeppers requested a review from a team as a code owner August 11, 2023 18:37
@rmarinho rmarinho merged commit ff02f57 into dotnet:main Aug 14, 2023
39 checks passed
@jonathanpeppers jonathanpeppers deleted the WindowOverlayLeaks branch August 14, 2023 13:27
rmarinho pushed a commit that referenced this pull request Aug 19, 2023
Context: #16346

This addresses the memory leak discovered by:

    src/Core/src/WindowOverlay/WindowOverlay.iOS.cs(92,40): error MA0001: Event 'OnTouch' could cause memory leaks in an NSObject subclass. Remove the event or add the [UnconditionalSuppressMessage("Memory", "MA0001")] attribute with a justification as to why the event will not leak.

I could reproduce a leak by writing a custom test.

Solved the problem by:

* Removed the `PassthroughView.OnTouch` event completely. We could just
  call `WindowOverlay.OnTappedInternal()` directly instead of going
  through an intermediate event.

* `WindowOverlay overlay` is now a `WeakReference<WindowOverlay>`.
@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
memory-leak 💦 Memory usage grows / objects live forever platform/iOS 🍎
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants