xamarin-macios icon indicating copy to clipboard operation
xamarin-macios copied to clipboard

CALayer APIs handling CGColorRef can crash due to GC timing

Open Therzok opened this issue 3 years ago • 1 comments

Steps to Reproduce

  1. See the discussion here https://github.com/xamarin/Xamarin.PropertyEditing/pull/821#discussion_r927049949
  2. CALayer's APIs that use CGColor should be used in high allocation rate conditions (i.e. backgroundColor)
  3. Create a lot of them, set them.

Expected Behavior

No crash

Actual Behavior

The native API might CFRetain the CGColorRef way too late, and dotnet precise GC scanning will mark it eligible for collection as soon as the PInvoke interop boundary is crossed.

Environment

Version information
dotnet workload list

macos                       SDK 6.0.300

Therzok avatar Aug 01 '22 21:08 Therzok

FYI @rolfbjarne maybe we should look at this when you or both of us get back?

chamons avatar Aug 02 '22 15:08 chamons

This seems to be a variation of #10146.

rolfbjarne avatar Aug 23 '22 08:08 rolfbjarne