From ba5f5e319807126eb35ced2cfabd56a7e358ad15 Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Wed, 31 May 2023 00:31:38 -0700 Subject: [PATCH] [js] allow manually release inference session (#16169) ### Description This change adds a new instance function (method) to type `InferenceSession` to allow users to manually release an inference session instance. #16131 depends on this change to work correctly. --- js/common/lib/inference-session-impl.ts | 4 ++++ js/common/lib/inference-session.ts | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/js/common/lib/inference-session-impl.ts b/js/common/lib/inference-session-impl.ts index c43ea7e419..65be994ef5 100644 --- a/js/common/lib/inference-session-impl.ts +++ b/js/common/lib/inference-session-impl.ts @@ -115,6 +115,10 @@ export class InferenceSession implements InferenceSessionInterface { return returnValue; } + async release(): Promise { + return this.handler.dispose(); + } + static create(path: string, options?: SessionOptions): Promise; static create(buffer: ArrayBufferLike, options?: SessionOptions): Promise; static create(buffer: ArrayBufferLike, byteOffset: number, byteLength?: number, options?: SessionOptions): diff --git a/js/common/lib/inference-session.ts b/js/common/lib/inference-session.ts index e32cd0dfa0..e9c3d2da80 100644 --- a/js/common/lib/inference-session.ts +++ b/js/common/lib/inference-session.ts @@ -306,6 +306,15 @@ export interface InferenceSession { // #endregion + // #region release() + + /** + * Release the inference session and the underlying resources. + */ + release(): Promise; + + // #endregion + // #region profiling /**