From d0a7a8fcd636493087d33e2bd20f9df8b3e5e7a7 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Wed, 9 Aug 2023 00:35:32 +0100 Subject: [PATCH] - Cleaned up disposal in LLamaContext - sealed some classes not intended to be extended --- LLama/LLamaContext.cs | 7 ++++--- LLama/LLamaWeights.cs | 2 +- LLama/Native/SafeLLamaContextHandle.cs | 2 +- LLama/Native/SafeLlamaModelHandle.cs | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/LLama/LLamaContext.cs b/LLama/LLamaContext.cs index 4516517d..3e526749 100644 --- a/LLama/LLamaContext.cs +++ b/LLama/LLamaContext.cs @@ -422,6 +422,8 @@ namespace LLama /// public virtual void Dispose() { + GC.SuppressFinalize(this); + _ctx.Dispose(); } @@ -429,12 +431,11 @@ namespace LLama /// The state of this model, which can be reloaded later /// public class State - : SafeHandleZeroOrMinusOneIsInvalid + : SafeLLamaHandleBase { internal State(IntPtr memory) - : base(true) + : base(memory) { - SetHandle(memory); } /// diff --git a/LLama/LLamaWeights.cs b/LLama/LLamaWeights.cs index 8226753f..cb237a70 100644 --- a/LLama/LLamaWeights.cs +++ b/LLama/LLamaWeights.cs @@ -9,7 +9,7 @@ namespace LLama /// /// A set of model weights, loaded into memory. /// - public class LLamaWeights + public sealed class LLamaWeights : IDisposable { private readonly SafeLlamaModelHandle _weights; diff --git a/LLama/Native/SafeLLamaContextHandle.cs b/LLama/Native/SafeLLamaContextHandle.cs index a6760b7d..49a31e65 100644 --- a/LLama/Native/SafeLLamaContextHandle.cs +++ b/LLama/Native/SafeLLamaContextHandle.cs @@ -8,7 +8,7 @@ namespace LLama.Native /// /// A safe wrapper around a llama_context /// - public class SafeLLamaContextHandle + public sealed class SafeLLamaContextHandle : SafeLLamaHandleBase { #region properties and fields diff --git a/LLama/Native/SafeLlamaModelHandle.cs b/LLama/Native/SafeLlamaModelHandle.cs index 01d2ca8c..182d503f 100644 --- a/LLama/Native/SafeLlamaModelHandle.cs +++ b/LLama/Native/SafeLlamaModelHandle.cs @@ -7,7 +7,7 @@ namespace LLama.Native /// /// A reference to a set of llama model weights /// - public class SafeLlamaModelHandle + public sealed class SafeLlamaModelHandle : SafeLLamaHandleBase { ///