Skip to content

Make IShape in MauiCALayer a WeakReference #28412

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

Merged
merged 2 commits into from
Mar 18, 2025

Conversation

MarcelStommel
Copy link
Contributor

Description of Change

Fixes a memory leak in MauiCALayer by making it's IShape? _shape field a weak reference, as proposed in the attached Issue.
The leak happens from the fact that most IShapes are also Views and thereby have access to the UI's NameScope and x:Nameed elements, which causes a ref-count cycle.

Issues Fixed

Fixes #26169
App to reproduce the memory leak / Test the fix: https://github.com/MarcelStommel/LayerLeak

@MarcelStommel MarcelStommel requested a review from a team as a code owner March 14, 2025 13:53
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Mar 14, 2025
Copy link
Contributor

Hey there @MarcelStommel! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz jsuarezruiz added area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) labels Mar 17, 2025
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

We have some specific tests to verify that controls not leaks here

[InlineData(typeof(RoundRectangle))]

But, not cover the scenario from https://github.com/MarcelStommel/LayerLeak/

Could you include a new test?

public class ShapeTests

@MarcelStommel
Copy link
Contributor Author

Added the Device Test as part of BorderTests, since that's also how I did it in https://github.com/MarcelStommel/LayerLeak/

(Sorry about the other GitHub account, I just had to test it on my private MacBook and that was just the easiest way to get the changes pushed.)
@dotnet-policy-service agree company="Quality Bytes GmbH"

@PureWeen PureWeen added this to the .NET 9 SR6 milestone Mar 18, 2025
@PureWeen PureWeen moved this from Todo to Approved in MAUI SDK Ongoing Mar 18, 2025
@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho rmarinho requested a review from jsuarezruiz March 18, 2025 13:51
@PureWeen PureWeen changed the base branch from main to inflight/current March 18, 2025 19:07
@PureWeen PureWeen merged commit 5f49a58 into dotnet:inflight/current Mar 18, 2025
74 of 128 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Mar 18, 2025
anandhan-rajagopal pushed a commit to anandhan-rajagopal/maui that referenced this pull request Mar 26, 2025
* Make IShape in MauiCALayer a WeakReference

* Added DeviceTest

---------

Co-authored-by: Rain336 <rain336@live.de>
anandhan-rajagopal pushed a commit to anandhan-rajagopal/maui that referenced this pull request Mar 26, 2025
* Make IShape in MauiCALayer a WeakReference

* Added DeviceTest

---------

Co-authored-by: Rain336 <rain336@live.de>
PureWeen pushed a commit that referenced this pull request Mar 26, 2025
* Make IShape in MauiCALayer a WeakReference

* Added DeviceTest

---------

Co-authored-by: Rain336 <rain336@live.de>
PureWeen pushed a commit that referenced this pull request Mar 26, 2025
* Make IShape in MauiCALayer a WeakReference

* Added DeviceTest

---------

Co-authored-by: Rain336 <rain336@live.de>
github-actions bot pushed a commit that referenced this pull request Mar 27, 2025
* Make IShape in MauiCALayer a WeakReference

* Added DeviceTest

---------

Co-authored-by: Rain336 <rain336@live.de>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[iOS] Investigate if MauiCALayer needs to use a weakreference for the IShape
5 participants