Skip to content

Fixed ListView leak caused by not disposed ContextActionsCell #28702

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
Apr 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ internal class ListViewDataSource : UITableViewSource
readonly WeakReference<UITableView> _uiTableView;
readonly WeakReference<FormsUITableViewController> _uiTableViewController;
protected readonly WeakReference<ListView> _list;
readonly HashSet<ContextActionsCell> _contextActionsCells = new();
bool _isDragging;
bool _setupSelection;
bool _selectionFromNative;
Expand Down Expand Up @@ -1113,6 +1114,10 @@ public override UITableViewCell GetCell(UITableView tableView, NSIndexPath index
SetCellBackgroundColor(platformCell, bgColor);
PreserveActivityIndicatorState(cell);
Performance.Stop(reference);

if(platformCell is ContextActionsCell contextActionsCell)
_contextActionsCells.Add(contextActionsCell);

return platformCell;
}

Expand Down Expand Up @@ -1495,12 +1500,16 @@ protected override void Dispose(bool disposing)

if (disposing)
{
if (!_list.TryGetTarget(out var list))
if (_list.TryGetTarget(out var list))
{
list.ItemSelected -= OnItemSelected;
WatchShortNameCollection(false);
}

foreach (var cell in _contextActionsCells)
cell.Dispose();
_contextActionsCells.Clear();

_templateToId = null;
}

Expand Down
Loading