CoreMlDelegate constructor

CoreMlDelegate({
  1. CoreMlDelegateOptions? options,
})

Creates a CoreML delegate with optional options.

When options is omitted a default set is allocated internally and freed again before returning: TfLiteCoreMlDelegateCreate copies what it needs out of the struct, so keeping it alive past the call served no purpose and leaked it for the life of the process. Caller-supplied options are left alone, since the caller owns them and may reuse them for another delegate.

Implementation

factory CoreMlDelegate({CoreMlDelegateOptions? options}) {
  final delegateOptions = options ?? CoreMlDelegateOptions();
  try {
    return CoreMlDelegate._(
      _coremlBinding.TfLiteCoreMlDelegateCreate(delegateOptions.base),
    );
  } finally {
    if (options == null) delegateOptions.delete();
  }
}