The Jerusalem PostFive killed in incident at Russian nuclear arms research center, officials sayDaily MaverickJapan court recognises overseas same-sex marriage in first-of-its-kind ruling, lawyers sayPunchYobe varsity VC hails Buni over approval of new staff allowancesBollywood HungamaBhuvan Bam faces FIR by Maharashtra Cyber Police over alleged obscene remarks at Parul UniversityInquirer EntertainmentVice Ganda, Kathryn Bernardo, Coco Martin lead TV5 2026 Christmas station IDUOLIrã diz que 3 petroleiros atingiram minas no Estreito de HormuzDeadlineFormer Warner Bros. UK Production Chief Kevin Trehy Joins In Plain Sight Group As Partner & CEOThe Straits TimesK-pop star Taemin to headline New Year’s Eve countdown party at Siloso BeachVanguardGive south-east chance to lead Nigeria, Obasanjo urges politiciansRappler[Inside the Newsroom] 5 questions and answers about Maria Ressa’s ICC testimonyCNN بالعربيةلغز عمره نحو 100 عام.. العثور على جثة محنطة في نهر جليدي بسويسراObservador DesportoSeguro e o seu comboio privado da CP
The Daily Newsstand · Free, Always
Friday, December 4, 2026
Automatic translation is active. Articles in other languages will open in English.Enable automatic translation of articles from other languages into English.

Three WinUI Crashes Prompt Fixes, Alongside a Proposal for Faster Layout

The article's text, from Joho no Todai's page.

Translate

Portrait and landscape photos can be arranged at a consistent height, with the layout recalculated when the window changes width. WinUI 3, a framework for building Windows interfaces, provides LinedFlowLayout for displays such as photo galleries.

Microsoft's design notes trace the layout to the photo gallery in Windows 11 File Explorer. It also works with ItemsView, a control for displaying content such as photos or product catalogs.

On December 4, a Microsoft WinUI developer published proposed fixes for three crashes involving layout cleanup, timers, and item selection.

All three have more to do with when work happens than with what appears on screen. Layout cleanup, timer events, and selection changes depend on the right thread and the correct ordering of events and internal state.

The thread that releases the last reference

The proposal describes Layout as the common base class for WinUI layouts. Several derived classes previously inherited ReferenceTracker individually.

For final cleanup, C++/WinRT checks for final_release on the root implementation type in the hierarchy. The relevant implementation was missing from Layout, so the derived classes' ReferenceTracker::final_release did not run.

Under .NET garbage collection, the final reference can be released on the finalizer thread, leaving the previous code to destroy a layout outside the UI thread.

Cleanup on the wrong thread could produce RPC_E_WRONG_THREAD when removing a tracking handle. The error could be swallowed internally, leaving stale tracking state behind. A later consistency check could then fail with 0xC0000420.

Destroying the layout could leave behind the state that tracked its references. The object's lifetime and its tracking state were not being cleaned up together.

The proposal moves ReferenceTracker to the base class, Layout. Derived classes forward reference-tracking operations there. Running destruction on the UI thread lets the code release the tracking state correctly.

The proposal also accounts for cases such as classes derived in C#. During final release, the code switches from AddRef() to NonDelegatingAddRef() so only the inner object's reference count is incremented while the outer object is being destroyed.

A timer could outlive layout cleanup

Another crash involves the timer LinedFlowLayout uses to recalculate the layout.

The previous timer's Tick callback used a direct pointer to the layout. There was no code to unregister the callback.

The callback could retain an object already being destroyed. Combined with the final-release issue, that could cause double destruction and the access violation 0xC0000005.

The proposal changes the timer to hold a weak reference and unregisters the callback during cleanup. A weak reference does not extend the object's lifetime, and the callback can check whether it can still acquire a strong reference.

The timer's startup and the removal of its callback belong to the same lifecycle. Both the conditions for starting the work and the state at the end need to be managed correctly.

Stale selection state after items are removed

Another crash involved deleting selected items from a list.

With templated ItemsView controls, data-source changes could reach the SelectionModel that tracks what is selected and the ItemsView control in the wrong order.

Removing a selected item sets a flag so selection can be updated later. The previous implementation scheduled that work at low priority and failed to clear the flag when applying the new selection.

The ordering issue could leave SelectionModel out of sync while ItemsView processed a change against stale state. An out-of-range lookup could then produce E_BOUNDS and crash with 0xC000027B.

The fix routes selection updates after collection changes through DispatcherQueue, a queue for deferred work. It raises priority from Low to Normal, sets the pending flag only after the work is queued successfully, and clears it when applying the selection begins.

The proposal both raises priority and gives selection updates one path through the code. Faster individual operations alone would leave notification ordering and pending state out of sync.

In the developer's published x64 Debug results, the selection and layout-release tests each crashed once before the fix. Each passed five runs after the fix.

The developer also reported passing all 33 ItemsView, 14 LinedFlowLayout, and 23 ItemsRepeater tests.

Layout CPU time fell 19.9% on ARM64

On December 3, another Microsoft WinUI developer submitted a performance proposal for LinedFlowLayout and its item management.

The usual layout path created two ordered maps keyed by tracker_ref, a reference-tracking type, to manage the widths of realized elements. It discarded both maps after every pass.

Looking up an item created a temporary tracker_ref, which required allocating and freeing a tracking handle. Walking the tree also required checking COM identity at each step. The code searched both maps.

A single width lookup therefore involved several bookkeeping operations. Reducing repeated work can help when resizing a window causes the layout to be recalculated.

The proposed key is the canonical IUnknown pointer that identifies each COM object, stored in a hash map (std::unordered_map). The map keeps one tracker_ref per item and reuses existing item data. It removes entries that are no longer needed at the end of the layout pass.

The ElementManager also repeatedly checked virtualization state, which determines which elements to realize based on the visible area. The developer said each lookup could query the realization rectangle through the WinRT ABI up to seven times.

Virtualization state stays stable during a layout pass, so the proposal looks it up when needed and caches it for reuse during the pass. The cache is cleared at layout boundaries and when the context changes.

The author tested on ARM64 with a 16-core Cobalt 100 CPU and 64 GB of memory. The test resized ten LinedFlowLayout instances of 1,000 items each at a fixed scroll position. It alternated between two Release builds that differed only by the proposed changes.

Across five measurements, median UI-thread CPU time per layout fell from 11.67 ms to 9.35 ms, a reduction of 19.9%. Elapsed time for a cycle of ten layouts fell from 140.4 ms to 114.6 ms, an 18.4% reduction. All five runs with the change beat all five baseline runs.

The measurements cover layout calculation under specific conditions. A resize test cannot establish how much faster File Explorer or Windows as a whole would become.

Reviewers also flagged that detaching and reattaching a layout could leave old row measurements in place. If the width remained the same, a needed calculation could be skipped. The proposal was updated to force measurement after reattachment and add a regression test.

The author reported passing 15 LinedFlowLayout tests and 14 collection-change tests for FlowLayout in an ARM64 Release build.

The internal work that shapes the interface

The crash fixes and the performance changes were both submitted for inclusion in WinUI. Any benefit to File Explorer itself will need to be measured after integration.

Both proposals ask how long internal layout state should be kept. The crash fixes clear references or pending flags when they are no longer needed. The performance proposal retains width information and drops it once it can no longer be reused.

One implementation crashes because stale tracking data survives. Another spends CPU time repeatedly discarding useful width data. Managing what each operation needs and how long that information stays valid can improve stability and responsiveness.

Photos line up, move as the window changes width, and can be deleted after selection. Those ordinary gestures require careful engineering behind the interface. Improving that work can make the time people spend using Windows a little better.

View the original on Joho no Todai →