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 TableView #18718

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

jonathanpeppers
Copy link
Member

Context: #18365

I could reproduce a leak in TableView by adding a parameterized test:

[InlineData(typeof(TableView))]
public async Task HandlerDoesNotLeak(Type type)

TableViewModelRenderer has two cycles:

  • TableView ->
  • TableViewRenderer ->
  • TableViewModelRenderer ->
  • TableView via View field

Second:

  • UITableView.Source ->
  • TableViewModelRenderer ->
  • UITableView via Table field

I left the Table and View fields in place to not break any public APIs. They are now unused and marked [Obsolete]. I used WeakReference<T> to solve these two cycles and the test now passes.

The analyzer warned about these locations, but we don't have the analyzer enabled on Microsoft.Maui.Controls yet:

#18318 (comment)

Context: dotnet#18365

I could reproduce a leak in `TableView` by adding a parameterized test:

    [InlineData(typeof(TableView))]
    public async Task HandlerDoesNotLeak(Type type)

`TableViewModelRenderer` has two cycles:

* `TableView` ->
* `TableViewRenderer` ->
* `TableViewModelRenderer` ->
* `TableView` via `View` field

* `UITableView.Source` ->
* `TableViewModelRenderer` ->
* `UITableView` via `Table` field

I left the `Table` and `View` fields in place to not break any public
APIs. They are now unused and marked `[Obsolete]`. I used
`WeakReference<T>` to solve these two cycles and the test now passes.

The analyzer warned about these locations, but we don't have the analyzer
enabled on `Microsoft.Maui.Controls` yet:

dotnet#18318 (comment)
@jonathanpeppers jonathanpeppers added platform/iOS 🍎 memory-leak 💦 Memory usage grows / objects live forever (sub: perf) labels Nov 13, 2023
@jonathanpeppers jonathanpeppers marked this pull request as ready for review November 14, 2023 01:42
@jonathanpeppers jonathanpeppers requested a review from a team as a code owner November 14, 2023 01:42
@jonathanpeppers jonathanpeppers added this to the .NET 8 + Servicing milestone Nov 14, 2023
@rmarinho rmarinho merged commit c10043f into dotnet:main Nov 17, 2023
47 checks passed
@jonathanpeppers jonathanpeppers deleted the TableViewLeaks branch November 17, 2023 23:10
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2023
@samhouts samhouts added the fixed-in-8.0.6 Look for this fix in 8.0.6 SR1! 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.6 Look for this fix in 8.0.6 SR1! 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.

3 participants