maui icon indicating copy to clipboard operation
maui copied to clipboard

[iOS] CollectionView has more logical children than items (potential memory leak)

Open emaf opened this issue 2 years ago • 1 comments

Description

On iOS, CollectionView ends up having more logical children than items. For instance, if you have 2 items and a Label as Item Template, and inspect the LogicalChildren, it ends up with 3 labels instead of 2. This third label is not visible on the app.

This works as expected on Android and Windows.

Some more details: _measurementCells is caching the cells that were bound so they can be reused, but those are cleared up while loading and not the ItemView children. Next time a cell is analyzed it is re-bound, so in the sample the first item is added twice.

  • https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs#L295
  • https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs#L352

Steps to Reproduce

Run the CollectionViewItemsWithFixedWidthAndDifferentHeight Core.DeviceTests for iOS.

Link to public reproduction project repository

https://github.com/dotnet/maui/blob/340fc257bf5bee3d8e8b5d834da4fcddac077d72/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs#L237

Version with bug

8.0.0-rc.2.9511

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

emaf avatar Nov 03 '23 20:11 emaf

Could be related to https://github.com/dotnet/maui/issues/14506

drasticactions avatar Nov 04 '23 04:11 drasticactions

I noticed something similar in ListView. In that case, the extra item was being created (seemingly) intentionally as part of the sizing strategy.

AdamEssenmacher avatar Feb 02 '24 10:02 AdamEssenmacher