as skiasharp uses the reference count when compiling as debug build to detect if a native object that has no references is about to be unref'd
if (GetInstanceNoLocks<TSkiaObject> (handle, out var instance)) {
// some object get automatically referenced on the native side,
// but managed code just has the same reference
if (unrefExisting && instance is ISKReferenceCounted refcnt) {
#if THROW_OBJECT_EXCEPTIONS
if (refcnt.GetReferenceCount () == 1)
throw new InvalidOperationException (
$"About to unreference an object that has no references. " +
$"H: {handle.ToString ("x")} Type: {instance.GetType ()}");
#endif
refcnt.SafeUnRef ();
}
return instance;