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

AsBitmap Leaks Memory #17

Open
SkyeHoefling opened this issue Aug 7, 2021 · 0 comments
Open

AsBitmap Leaks Memory #17

SkyeHoefling opened this issue Aug 7, 2021 · 0 comments

Comments

@SkyeHoefling
Copy link
Contributor

Description

When using AsBitmap() it leaks memory and causes application failures that depend on the Bitmap object. This is due to the custom pointer we create and manually setting the stride.

Reproduction Steps

Load a large raw image using the following algorithm

Bitmap GetMyImage()
{
    using (var image = new RawImage("/path/to/raw/file"))
    using (var raw = image.UnpackRaw())
    {
        raw.Process(new DcrawProcessor());
        using (var processed = raw.AsProcessedImage())
            return processed.AsBitmap();
    }
}

The above code will still leak even if you manually managed the IDisposable and implement this inside of a wrapper. Once you start zooming in on the bitmap in the UI application it will quickly run out of memory

Workaround

The best workaround I could find was converting the image to a Bitmap saving it to disk and then loading the .bmp file into memory and returning it.

Bitmap GetMyImage()
{
    using (var image = new RawImage("/path/to/raw/file"))
    using (var raw = image.UnpackRaw())
    {
        raw.Process(new DcrawProcessor());
        using (var processed = raw.AsProcessedImage())
        using (var bitmap = processed.AsBitmap())
            bitmap.Save("temp.bmp", ImageFormat.Bmp);

        return new Bitmap("temp.bmp");
    }
}
@SkyeHoefling SkyeHoefling changed the title AsBitmap is Leaks Memory AsBitmap Leaks Memory Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant