From 45a573b9295457c21984b02f3eecdb53d32cde85 Mon Sep 17 00:00:00 2001 From: HarishwaranVijayakumar Date: Tue, 7 Apr 2026 12:57:38 +0530 Subject: [PATCH] Add fix --- src/Essentials/src/MediaPicker/MediaPicker.ios.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs index 5e7ca0389f65..85b2ca5dc484 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs @@ -502,6 +502,14 @@ class PhotoPickerDelegate : PHPickerViewControllerDelegate public override void DidFinishPicking(PHPickerViewController picker, PHPickerResult[] results) { + // Null out the presentation delegate handler before dismiss to prevent a GC race condition. + // Without this, Dispose() on PhotoPickerPresentationControllerDelegate can fire tcs.TrySetResult([]) + // while the async CompletedHandler is still processing (especially slow for HEIC transcoding). + if (picker.PresentationController?.Delegate is PhotoPickerPresentationControllerDelegate pd) + { + pd.Handler = null; + } + var captured = results?.Length > 0 ? results : []; picker.DismissViewController(true, () => CompletedHandler?.Invoke(captured)); }