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
{
///