dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.27k stars 1.76k forks source link

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

Open emaf opened 1 year ago

emaf commented 1 year ago

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.

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

drasticactions commented 1 year ago

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

AdamEssenmacher commented 10 months ago

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