-
-
Notifications
You must be signed in to change notification settings - Fork 443
Closed
Description
Prerequisites
- I have written a descriptive issue title
- I have verified that I am using the latest version of Magick.NET
- I have searched open and closed issues to ensure it has not already been reported
Description
My issue seems similar to this comment in #340, but it doesn't seem to have ever been addressed. It appears that MagickImage.Resize has a memory leak. I have come to this conclusion experimentally rather than via debugging the library manually, but the snipped code below does not leak memory if I comment out the image.Resize(...) line, whereas it does leak memory otherwise. I have observed this in Docker (based on the image mcr.microsoft.com/dotnet/core/sdk:2.2).
Steps to Reproduce
The container's memory balloons if I continuously make requests to the endpoint containing this code. I imagine simply calling this code in a while loop would exhibit the same behavior (I can provide the full controller if necessary, but figured I would limit it for brevity).
// ImageController.cs
var format = ...; // computed from URL
// imageData is a byte array
Debug.Log($"Creating image object...");
using (var image = new MagickImage(imageData, format))
{
if (image.Width <= 512 && image.Height <= 512)
{
var str = new MemoryStream(imageData);
Debug.Log($"Smaller than 512, returning...");
return File(str, http.ResponseHeaders["Content-Type"]);
}
int targetWidth = Math.Min(image.Width, 512);
int targetHeight = Math.Min(image.Height, 512);
var size = new MagickGeometry(targetWidth, targetHeight);
Debug.Log($"Resizing...");
// Commenting out this line prevents the code from leaking memory
image.Resize(size);
// Save the result
var data = image.ToByteArray();
Debug.Log($"Resized, returning...");
{
var str = new MemoryStream(data);
return File(str, http.ResponseHeaders["Content-Type"]);
}
}System Configuration
- Magick.NET version: Magick.NET-Q8-AnyCPU 7.21.1.0
- Environment (Operating system, version and so on): Docker Desktop for Windows 10, Docker on Amazon Linux 15. Container based on mcr.microsoft.com/dotnet/core/sdk:2.2
- Additional information:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels