diff --git a/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs b/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs
index 0c458dc00..ced91fec7 100644
--- a/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs
+++ b/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs
@@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Memory.Internals
{
internal partial class UniformUnmanagedMemoryPool
#if !NETSTANDARD1_3
- // In case UniformUnmanagedMemoryPool is finalized, we prefer to run it's finalizer after the guard finalizers,
+ // In case UniformUnmanagedMemoryPool is finalized, we prefer to run its finalizer after the guard finalizers,
// but we should not rely on this.
: System.Runtime.ConstrainedExecution.CriticalFinalizerObject
#endif
diff --git a/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs
index c63c0b637..d9734baea 100644
--- a/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs
+++ b/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs
@@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Memory
private static long GetDefaultMaxPoolSizeBytes()
{
#if NETCORE31COMPATIBLE
- // On .NET Core 3.1+, determine the pool as portion of the total available memory.
+ // On 64 bit .NET Core 3.1+, set the pool size to a portion of the total available memory.
// There is a bug in GC.GetGCMemoryInfo() on .NET 5 + 32 bit, making TotalAvailableMemoryBytes unreliable:
// https://github.com/dotnet/runtime/issues/55126#issuecomment-876779327
if (Environment.Is64BitProcess || !RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.0"))
diff --git a/src/ImageSharp/Memory/Allocators/UnmanagedMemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/UnmanagedMemoryAllocator.cs
index 9b0869c40..74197b0a1 100644
--- a/src/ImageSharp/Memory/Allocators/UnmanagedMemoryAllocator.cs
+++ b/src/ImageSharp/Memory/Allocators/UnmanagedMemoryAllocator.cs
@@ -7,14 +7,15 @@ using SixLabors.ImageSharp.Memory.Internals;
namespace SixLabors.ImageSharp.Memory
{
+ ///
+ /// A implementation that allocates memory on the unmanaged heap
+ /// without any pooling.
+ ///
internal class UnmanagedMemoryAllocator : MemoryAllocator
{
private readonly int bufferCapacityInBytes;
- public UnmanagedMemoryAllocator(int bufferCapacityInBytes)
- {
- this.bufferCapacityInBytes = bufferCapacityInBytes;
- }
+ public UnmanagedMemoryAllocator(int bufferCapacityInBytes) => this.bufferCapacityInBytes = bufferCapacityInBytes;
protected internal override int GetBufferCapacityInBytes() => this.bufferCapacityInBytes;
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs
index 2e690ce9b..7c58c9c01 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs
@@ -50,13 +50,7 @@ namespace SixLabors.ImageSharp.Memory
return ((IList>)this.source).GetEnumerator();
}
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- this.View.Invalidate();
- }
- }
+ public override void Dispose() => this.View.Invalidate();
}
}
}
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs
index a59602efa..3b9241383 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs
@@ -129,9 +129,9 @@ namespace SixLabors.ImageSharp.Memory
return this.memoryOwners.Select(mo => mo.Memory).GetEnumerator();
}
- protected override void Dispose(bool disposing)
+ public override void Dispose()
{
- if (this.IsDisposed || !disposing)
+ if (this.IsDisposed)
{
return;
}
@@ -193,7 +193,9 @@ namespace SixLabors.ImageSharp.Memory
b.View = new MemoryGroupView(b);
}
- // No-ownership
+ // When the MemoryGroup points to multiple buffers via `groupLifetimeGuard`,
+ // the lifetime of the individual buffers is managed by the guard.
+ // Group buffer IMemoryOwner-s d not manage ownership.
private sealed class ObservedBuffer : MemoryManager
{
private readonly UnmanagedMemoryHandle handle;
diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs
index 0fcbd6f96..cdd8e6a75 100644
--- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs
+++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs
@@ -45,13 +45,7 @@ namespace SixLabors.ImageSharp.Memory
public abstract Memory this[int index] { get; }
///
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected abstract void Dispose(bool disposing);
+ public abstract void Dispose();
///
public abstract MemoryGroupEnumerator GetEnumerator();
diff --git a/tests/ImageSharp.Tests/Image/LargeImageIntegrationTests.cs b/tests/ImageSharp.Tests/Image/LargeImageIntegrationTests.cs
index 1f0963aac..b2ee9d673 100644
--- a/tests/ImageSharp.Tests/Image/LargeImageIntegrationTests.cs
+++ b/tests/ImageSharp.Tests/Image/LargeImageIntegrationTests.cs
@@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests
}
[Fact]
- public void PreferContiguousImageBuffers_CreateImage_MaximumPoolSizeMegabytes()
+ public void PreferContiguousImageBuffers_CreateImage_BufferIsContiguous()
{
// Run remotely to avoid large allocation in the test process:
RemoteExecutor.Invoke(RunTest).Dispose();