Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image resizing increases TotalUndisposedAllocationCount #2100

Closed
4 tasks done
BaileyMillerSSI opened this issue Apr 28, 2022 · 1 comment
Closed
4 tasks done

Image resizing increases TotalUndisposedAllocationCount #2100

BaileyMillerSSI opened this issue Apr 28, 2022 · 1 comment
Labels

Comments

@BaileyMillerSSI
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

2.1.1

Other ImageSharp packages and versions

None

Environment (Operating system, version and so on)

Window 11 Pro, Version 10.0.22000 Build 22000

.NET Framework version

net6.0

Description

When doing a simple image resize the TotalUndisposedAllocationCount increases per image resized.

Steps to Reproduce

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Diagnostics;

var photos = Directory.EnumerateFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "*.png", SearchOption.AllDirectories).Take(5);

foreach (var photo in photos)
{
    Console.WriteLine($"Number of undisposed ImageSharp buffers: {MemoryDiagnostics.TotalUndisposedAllocationCount}");

    using (var outputStream = new MemoryStream())
    using (var imageStream = File.OpenRead(photo))
    {
        var (image, format) = await Image.LoadWithFormatAsync(stream: imageStream);

        image
            .Mutate(x =>
                x.Resize(image.Width/2, 0, KnownResamplers.Lanczos3));

        await image.SaveAsync(outputStream, format);

        outputStream.Position = 0;

        Console.WriteLine($"Number of undisposed ImageSharp buffers: {MemoryDiagnostics.TotalUndisposedAllocationCount}");
    }
}

Images

Snapchat-1117624853

@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Apr 28, 2022

You're not disposing of the image in your sample code.

 outputStream.Position = 0;
+ image.Dispose();

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants