dotnet / dotnet/maui

WinUi CollectionView is not recycling containers.

Open
#8,151 9 comments 3 reactions 0 assignees View on GitHub
area-controls-collectionview perf/general platform/windows s/triaged s/verified t/bug t/perf/9.0.40
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 10h
Merged PRs (30d)
297

Description

### Description

The WinUI CollectionView does not recycle item-containers and instead creates a new item-container every time some data scrolls into view.

### Steps to Reproduce

### Minimum repo:
https://github.com/Keflon/MauiRecycleBug

### Steps:

Create a CollectionView
Fill it with items
Scroll up and down in the CollectionView
For the sample, watch the Debug output.

### Android

A small number of CollectionItem instances are created and these are recycled.
Example Debug output:
*Created CollectionItem. InstanceId: 12. There are 12 instances allocated*

### WinUI

A new CollectionItem is created every time an instance scrolls into view.
Example Debug output:
Created CollectionItem. InstanceId: 133. There are 133 instances allocated

Scrolling quickly to the end and back (e.g. by dragging the scroll-bar) causes a **CRASH**

Scrolling slowly can eventually instigate an item being garbage-collected
Example Debug output:
*Collected CollectionItem. InstanceId: 9. There are 129 instances allocated*

**Related:** The DataTemplate in the sample code has a CheckBox.
1. The CheckBox is rendered incorrectly until the Window is resized horizontally.
1. Should I open a new bug for this?
1. Having the CheckBox present in the DataTemplate causes a LOT of memory to be consumed, leading to an `OutOfMemoryException`
1. Is this a separate bug?

### Version with bug

6.0.400 (current)

### Last version that worked well

6.0 Release Candidate 3

### Affected platforms

Windows

### Affected platform versions

Latest

### Did you find any workaround?

Note: I can't confirm 100% this worked in the previous release because I don't know how to roll-back, but I'm certain this is a new problem.

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.