Skip to content

Embeddings onnxtextembedder dispose

github-actions[bot] edited this page Aug 26, 2026 · 24 revisions

Development build. This page describes main, not a released package. The latest published Lodestar.Embeddings is 0.4.0 — read its documentation.

OnnxTextEmbedder.Dispose

Release the native model session.

public void Dispose()

Exampleusing is the whole of it.

using Lodestar.Embeddings.Onnx;

using var embedder = new OnnxTextEmbedder("model.onnx");
float[] vector = embedder.Embed([101, 2054, 102], [1, 1, 1]);
// Dispose runs at the end of the scope.

Remarks — the session is native memory, not managed, so it is not reclaimed by a garbage collection and a forgotten embedder holds the model until the process ends. Loading several models in a long-running service without disposing is how that becomes visible.

Disposing twice is safe. Calling Embed or EmbedBatch afterwards is not, and throws.

Applies to — net10.0, netstandard2.0.

See alsoOnnxTextEmbedder.

Lodestar

Project

Clone this wiki locally