HandyOrg / HandyControl

Contains some simple and commonly used WPF controls
https://handyorg.github.io/
MIT License
6.18k stars 1.04k forks source link

ImageViewer、ImageBrowser显示高分辨率图片内存泄露 #1482

Closed HubTonight closed 4 months ago

HubTonight commented 1 year ago

Describe the bug

ImageViewer、ImageBrowser显示高分辨率图片内存泄露,使用7518 x 2048分辨率1.43MB大小图片多打开关闭几次ImageView或者ImageBrowser后内存泄露,内存无法释放

Steps to reproduce the bug

1.将HandyControlDemo_Shared项目下ViewModel/Controls/ImageBrowserDemoViewModel.cs文件中

public RelayCommand OpenImgCmd => new(() =>
        new ImageBrowser(new Uri("pack://application:,,,/Resources/Img/1.jpg")).Show());

Uri 部分替换为本地高分辨率图片; 2.使用HandyControlDemo_Net_GE45项目、.net7.0-windows环境Release模式编译项目; 3.运行Release/net7.0-windows文件夹下HandyControlDemo.exe后在【“控件”->“图片浏览器”->"点击打开图片浏览器"】多打开关闭几次后出现内存泄露。

Expected behavior

No response

Screenshots

No response

NuGet package version

HandyControl 3.4.0

IDE

Visual Studio 2022

Framework type

No response

Windows version

Windows 11 (22000)

Additional context

No response

liuwenchang commented 8 months ago

这个我测试发现wpf 里只要加image控件就会这样,wpf本身框架问题,https://github.com/dotnet/wpf/issues/2397,可以这样规避这个问题 在ImageViewer.cs里,加函数 public void ResetImageMain() { ImageSource = null; _imageMain.Source = null; _imageMain.UpdateLayout(); }

在ImageBrowser.cs里覆盖Close函数 public new void Close() { _imageViewer.ResetImageMain(); base.Close(); }