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

[Peek] Previewer icon bitmaps are never deleted, leaking memory #34527

Open
daverayment opened this issue Sep 1, 2024 · 1 comment
Open

[Peek] Previewer icon bitmaps are never deleted, leaking memory #34527

daverayment opened this issue Sep 1, 2024 · 1 comment
Labels
Issue-Bug Something isn't working Product-Peek Refers to Peek Powertoys Status-In progress This issue or work-item is under development

Comments

@daverayment
Copy link
Contributor

Microsoft PowerToys version

0.83.0

Installation method

PowerToys auto-update

Running as admin

No

Area(s) with issue?

Peek

Steps to reproduce

Use Peek to preview an audio file, a 'special folder' (e.g. one containing images where their thumbnails are shown on the folder itself), an unsupported file, or a drive. The icon subsequently displayed in the Peek UI is retrieved using the IconHelper in the Peek.FilePreviewer.Previewers.Helpers namespace.

In IconHelper.GetImageAsync(), the handle for the retrieved icon bitmap is set to IntPtr.Zero immediately after being retrieved, instead of being disposed of using NativeMethods.DeleteObject in the finally block. The handle's resource is never freed and remains in memory:

    ...
    imageSource = hr == HResult.Ok ? await BitmapHelper.GetBitmapFromHBitmapAsync(hbitmap, isSupportingTransparency, cancellationToken) : null;

    hbitmap = IntPtr.Zero;
}
finally
{
    if (hbitmap != IntPtr.Zero)
    {
        NativeMethods.DeleteObject(hbitmap);
    }

I have a fix for this and other thumbnail-related issues. As they are interrelated, I would like to tackle them in a single PR.

✔️ Expected Behavior

After navigating to an item where an icon graphic is shown in the previewer, the unmanaged bitmap resource is correctly freed.

❌ Actual Behavior

The unmanaged bitmap memory for the icon is not freed, taking up process memory.

Other Software

No response

@daverayment daverayment added Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Sep 1, 2024
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@davidegiacometti davidegiacometti added the Product-Peek Refers to Peek Powertoys label Sep 2, 2024
daverayment added a commit to daverayment/PowerToys that referenced this issue Sep 2, 2024
…Fixed ImagePreviewer thumbnails being created and then not used. Refactored ImagePreviewer. Fixes microsoft#34490. Fixes microsoft#34527
@htcfreek htcfreek added Status-In progress This issue or work-item is under development and removed Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Product-Peek Refers to Peek Powertoys Status-In progress This issue or work-item is under development
Projects
None yet
Development

No branches or pull requests

3 participants