releaseOrtValue method

  1. @override
Future<void> releaseOrtValue(
  1. String valueId
)

Releases native resources associated with an OrtValue

valueId is the ID of the OrtValue to release

Implementation

@override
Future<void> releaseOrtValue(String valueId) async {
  try {
    // Check if the tensor exists
    if (!_ortValues.containsKey(valueId)) {
      // If not found, return successfully (similar to other platforms)
      return;
    }

    // Get the tensor
    final tensor = _ortValues[valueId]!;

    // Call dispose method if available to free resources
    if (tensor.has('dispose')) {
      callMethod(tensor, 'dispose', []);
    }

    // Remove the tensor from our map
    _ortValues.remove(valueId);
  } catch (e) {
    // Even if release fails, attempt to remove from the map
    _ortValues.remove(valueId);
  }
}