From 54808ea21a6df5d336a9bc94a31ed58e78ff3c64 Mon Sep 17 00:00:00 2001 From: antonfirsov Date: Tue, 17 Feb 2026 17:15:55 +0100 Subject: [PATCH] Undo #2025 --- ...niformUnmanagedMemoryPoolMemoryAllocator.cs | 18 ++++-------------- ...UniformUnmanagedPoolMemoryAllocatorTests.cs | 13 ------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs index 10defe6cdf..d5cd329f1b 100644 --- a/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs +++ b/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs @@ -71,10 +71,6 @@ internal UniformUnmanagedMemoryPoolMemoryAllocator( this.nonPoolAllocator = new UnmanagedMemoryAllocator(unmanagedBufferSizeInBytes); } - // This delegate allows overriding the method returning the available system memory, - // so we can test our workaround for https://github.com/dotnet/runtime/issues/65466 - internal static Func GetTotalAvailableMemoryBytes { get; set; } = () => GC.GetGCMemoryInfo().TotalAvailableMemoryBytes; - /// protected internal override int GetBufferCapacityInBytes() => this.poolBufferSizeInBytes; @@ -155,20 +151,14 @@ internal override MemoryGroup AllocateGroupCore( private static long GetDefaultMaxPoolSizeBytes() { - // On 64 bit set the pool size to a portion of the total available memory. - // https://github.com/dotnet/runtime/issues/55126#issuecomment-876779327 if (Environment.Is64BitProcess) { - long total = GetTotalAvailableMemoryBytes(); - - // Workaround for https://github.com/dotnet/runtime/issues/65466 - if (total > 0) - { - return (long)((ulong)total / 8); - } + // On 64 bit set the pool size to a portion of the total available memory. + GCMemoryInfo info = GC.GetGCMemoryInfo(); + return info.TotalAvailableMemoryBytes / 8; } - // Stick to a conservative value of 128 Megabytes on other platforms and 32 bit .NET 5.0: + // Stick to a conservative value of 128 Megabytes on 32 bit. return 128 * OneMegabyte; } } diff --git a/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedPoolMemoryAllocatorTests.cs b/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedPoolMemoryAllocatorTests.cs index c1f5b44bf7..1d185a0de9 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedPoolMemoryAllocatorTests.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedPoolMemoryAllocatorTests.cs @@ -409,19 +409,6 @@ private static void AllocateSingleAndForget(UniformUnmanagedMemoryPoolMemoryAllo g = null; } - [Fact] - public void Issue2001_NegativeMemoryReportedByGc() - { - RemoteExecutor.Invoke(RunTest).Dispose(); - - static void RunTest() - { - // Emulate GC.GetGCMemoryInfo() issue https://github.com/dotnet/runtime/issues/65466 - UniformUnmanagedMemoryPoolMemoryAllocator.GetTotalAvailableMemoryBytes = () => -402354176; - _ = MemoryAllocator.Create(); - } - } - [Fact] public void Allocate_OverLimit_ThrowsInvalidMemoryOperationException() {