- Notifications
You must be signed in to change notification settings - Fork1.1k
Improve UIA Provider Cleanup Logic for Virtual ListView Items#13953
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Improve UIA Provider Cleanup Logic for Virtual ListView Items#13953
Conversation
e987626 todaf7e8dComparedaf7e8d toc0e5c79Comparecodecovbot commentedOct 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@## main #13953 +/- ##===================================================+ Coverage 77.15093% 77.15120% +0.00027%=================================================== Files 3276 3276 Lines 645116 645141 +25 Branches 47705 47709 +4 ===================================================+ Hits 497713 497734 +21+ Misses 143716 143712 -4- Partials 3687 3695 +8
Flags with carried forward coverage won't be shown.Click here to find out more. 🚀 New features to boost your workflow:
|
KlausLoeffelmann left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think, with this approach, we are "unvirtualize" ListView items and prevent them from being GC-collected. Let's discuss this and make sure, I am not missing anything.
LeafShi1 commentedOct 17, 2025
@KlausLoeffelmann I updated the PR, please review it again. Added _uiaAccessedIndices to track only the indices accessed by UIA in virtual mode, _uiaAccessedIndices stores only integer indices, not ListViewItem objects. Since there is no strong reference to the actual items, the GC can still reclaim them when they are no longer used. |
| for(inti=0;i<Items.Count;i++) | ||
| if(VirtualMode) | ||
| { | ||
| foreach(intindexin_uiaAccessedIndices) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
In virtual mode, ListViewItem objects aren't real objects; instead, they're dynamically generated using the RetrieveVirtualItem method.
If the data source changes (such as insertions, deletions, or sorting), the original index may no longer correspond to the original item.
Uh oh!
There was an error while loading.Please reload this page.
Fixes#13922
Root Cause
When
ListView.VirtualMode = true, the current implementation ofReleaseUiaProvider()iterates over all indices (Items.Count) and callsItems.GetItemByIndex().This triggers
OnRetrieveVirtualItemfor every index, forcing creation of all virtual items even if they were never displayed or accessed.Result in:
Severe performance degradation for large virtual lists (e.g., tens of thousands of items).
High memory pressure due to unnecessary ListViewItem instantiation.
UI freeze during control disposal.
Proposed changes
This PR improves the cleanup logic for UI Automation (UIA) providers in ListView when operating in
VirtualMode = true. Specifically:_uiaAccessedIndicestracking mechanism to record only the indices of items whoseAccessibilityObjectwas created by UIA.ReleaseUiaProviderto selectively release UIA providers only for accessed items, avoiding full traversal ofVirtualListSizeand improving performance.NotifyUiaCreatedis called duringAccessibilityObjectcreation to maintain accurate tracking.RetrieveVirtualItemduring cleanup, which previously caused unnecessary item creation and severe performance degradation in large virtual lists.Customer Impact
Regression?
Risk
Screenshots
Before
When closing the form containing the ListView (in virtual mode), followed by closing the main form, the application experienced a noticeable delay.
BeforeChanges.mp4
After
When closing the form containing the ListView (in virtual mode), and subsequently closing the main form, the main form closes immediately with no noticeable delay.
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers:Open in CodeFlow