Skip to content

Commit 3150240

Browse files
CopilotPureWeen
authored andcommitted
Add WeakReference test for CollectionViewHandler2 to verify no handler leak
Co-authored-by: PureWeen <[email protected]>
1 parent 95d3fff commit 3150240

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ public async Task CollectionViewDoesNotLeakWithDefaultItemsLayout()
257257
SetupBuilder();
258258

259259
WeakReference weakCollectionView = null;
260+
WeakReference weakHandler = null;
260261

261262
await InvokeOnMainThreadAsync(async () =>
262263
{
@@ -274,15 +275,21 @@ await InvokeOnMainThreadAsync(async () =>
274275
// Verify handler is created
275276
Assert.NotNull(handler);
276277

278+
// Store weak reference to the handler
279+
weakHandler = new WeakReference(handler);
280+
277281
// Disconnect the handler
278282
((IElementHandler)handler).DisconnectHandler();
279283
});
280284

281285
// Force garbage collection
282-
await AssertionExtensions.WaitForGC(weakCollectionView);
286+
await AssertionExtensions.WaitForGC(weakCollectionView, weakHandler);
283287

284288
// Verify the CollectionView was collected
285289
Assert.False(weakCollectionView.IsAlive, "CollectionView should have been garbage collected");
290+
291+
// Verify the handler was collected
292+
Assert.False(weakHandler.IsAlive, "CollectionViewHandler2 should have been garbage collected");
286293
}
287294

288295
/// <summary>

0 commit comments

Comments
 (0)