You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Use GC.KeepAlive() to prevent early collection of method parameters #719
Depending on "various factors", it is possible that Mono's GC will decide that windowToken -- used on line (1) -- is eligible for collection on line (2), when it must be kept alive until after line (3) completes execution.
If windowTokenisn't kept alive, then it could be finalized before/during the InvokeAbstractBooleanMethod() invocation, which could invalidate/change windowToken.Handle, and cause lots of head scratching, confusion, and app crashes.
The fix? We need to emit a GC.KeepAlive() for all reference types until after the Invoke* invocation has completed:
A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.
Fix included in Xamarin.Android SDK version 11.1.0.15.
Fix included on macOS in Visual Studio 2019 for Mac version 8.8 Preview 4. To try the Preview version that includes the fix, check for the latest updates on the Previewupdater channel.
Fix included on macOS in Visual Studio 2019 for Mac version 8.8. To get the new version that includes the fix, check for the latest updates on the Stableupdater channel.
Activity
[-]Need to use GC.KeepAlive()[/-][+]Use GC.KeepAlive() to prevent early collection of method parameters[/+][generator] Use GC.KeepAlive for reference type method parameters. (#722
Bump to xamarin/Java.Interop/d16-8@79d95334
Bump to xamarin/Java.Interop/d16-8@79d95334 (#5139)
[generator] Use GC.KeepAlive for reference type method parameters.
[generator] Use GC.KeepAlive for reference type method parameters. (#725
brendanzagaeski commentedon Oct 13, 2020
Release status update
A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.
Fix included in Xamarin.Android SDK version 11.1.0.15.
Fix included on Windows in Visual Studio 2019 version 16.8 Preview 4. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.
Fix included on macOS in Visual Studio 2019 for Mac version 8.8 Preview 4. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.
Bump to xamarin/java.interop/master@b991bb86 (#5198)
brendanzagaeski commentedon Nov 10, 2020
Release status update
A new Release version of Xamarin.Android has now been published that includes the fix for this item.
Fix included in Xamarin.Android SDK version 11.1.0.17.
Fix included on Windows in Visual Studio 2019 version 16.8. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.
Fix included on macOS in Visual Studio 2019 for Mac version 8.8. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.
[linker] Add AddKeepAlivesStep (#5278)
[generator] Use GC.KeepAlive for reference type method parameters. (#725