Looking into the generated `Trampolines.g.cs` files we can spot some code patterns that looks like: ```csharp return NSArray.FromNSObjects(retval).Handle; ``` This is incorrect as the GC can dispose of the managed `NSArray` before the `Handle` is used again. If unlucky (the window of opportunity is small but exist) that can `dealloc` the native `NSArray` before the `Handle` is used again. See also: https://github.com/xamarin/xamarin-macios/issues/10146
Activity
rolfbjarne commentedon Sep 6, 2021
One potential solution would be to retain/autorelease the return value:
spouliot commentedon Sep 7, 2021
That's simpler than what I had in mind [0] but I'd be worried about a tight-loop calling that trampoline.
[0] ideally we would avoid a managed
NSArrayto be created since we're returning an handle anywayrolfbjarne commentedon Apr 8, 2025
This has been fixed now (4c22a30).