Skip to content

[ios] fix memory leak in WindowOverlay#16700

Merged
rmarinho merged 1 commit intodotnet:mainfrom
jonathanpeppers:WindowOverlayLeaks
Aug 14, 2023
Merged

[ios] fix memory leak in WindowOverlay#16700
rmarinho merged 1 commit intodotnet:mainfrom
jonathanpeppers:WindowOverlayLeaks

Conversation

@jonathanpeppers
Copy link
Copy Markdown
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 perf/memory-leak 💦 Memory usage grows / objects live forever (sub: perf) labels Aug 11, 2023
@jsuarezruiz
Copy link
Copy Markdown
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
@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
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 perf/memory-leak 💦 Memory usage grows / objects live forever (sub: perf) platform/ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants