closeSession method

  1. @override
Future<void> closeSession(
  1. String sessionId
)

Close a session

sessionId is the ID of the session to close

Implementation

@override
Future<void> closeSession(String sessionId) async {
  try {
    // Check if the session exists
    if (!_sessions.containsKey(sessionId)) {
      // If session not found, return successfully (similar to how other platforms handle this case)
      return;
    }

    final session = _sessions[sessionId]!;

    // Call the release method to properly free memory resources
    // In ONNX Runtime JavaScript API, the method to release resources is 'release()'
    try {
      callMethod(session, 'release', []);
    } catch (e) {
      // print('Error releasing ONNX session: $e');
      // Even if release fails, we should still remove the session from our map
    }

    // Remove session from the map
    _sessions.remove(sessionId);
  } catch (e) {
    // Log error but don't throw exception to match behavior of other platforms
    // print('Error closing session: $e');
  }
}