From 0c2cff0e1c5a0f2fe93d2e7e4f31054629f9eaf9 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Mon, 12 Feb 2024 02:58:35 +0000 Subject: [PATCH] Added a Finalizer for `Conversation` in case it is not correctly disposed. --- LLama/Batched/Conversation.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/LLama/Batched/Conversation.cs b/LLama/Batched/Conversation.cs index a699bb66..b3ce97dd 100644 --- a/LLama/Batched/Conversation.cs +++ b/LLama/Batched/Conversation.cs @@ -54,6 +54,11 @@ public sealed class Conversation _end = end; } + ~Conversation() + { + Dispose(); + } + /// /// End this conversation, freeing all resources used by it /// @@ -66,6 +71,9 @@ public sealed class Conversation // Remove this conversation from the KV cache Executor.Context.NativeHandle.KvCacheRemove(ConversationId, 0, _end); + + // Prevent finalizer from running + GC.SuppressFinalize(this); } private void AssertNotDisposed()