Skip to content

[ios] fix memory leak in TableView#18718

Merged
rmarinho merged 1 commit intodotnet:mainfrom
jonathanpeppers:TableViewLeaks
Nov 17, 2023
Merged

[ios] fix memory leak in TableView#18718
rmarinho merged 1 commit intodotnet:mainfrom
jonathanpeppers:TableViewLeaks

Conversation

@jonathanpeppers
Copy link
Copy Markdown
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 perf/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
@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! 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.

3 participants