Use the ArrayPool API in .NET Standard 2.1 or later to reduce the creation of LOH objects. #1812
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I'm a programmer from China. The text below is translated using AI, as my English isn't proficient enough for direct conversation, though I'm actively working to improve.
I'm developing a personal web application using Magick.NET. During development, I noticed that converting RAW photo files to JPG generates a significant number of LOH (Large Object Heap) objects. After reviewing the source code, I traced the issue to the ResizeBytes method in the ByteArrayWrapper class. This method reallocates byte arrays based on the length returned by localized code, causing unused arrays to accumulate in the LOH. To address this, I implemented the ArrayPool API to reduce LOH allocations. After the modifications, the program now generates only a small number of LOH objects per run, drastically reducing LOH allocation.
My environment uses .NET 8, and the ArrayPool API is only available in .NET Standard 2.1 or later, meaning it cannot compile in versions prior to .NET Standard 2.0 (e.g., .NET Framework 4.6.1).
Below are screenshots of how my interface uses Magick.NET and the memory monitoring. Each LOH change in the screenshots corresponds to one program execution.
Before:





After:
Here are my test photos, captured using a Nikon Z8 in uncompressed RAW format.
https://github.com/Wak1Z2/Magick.NET/tree/main/testImage
Thank you for reviewing my code! This is my first attempt at contributing to an open-source library.