From bec6754aa306d7b84e6cfd0264c0f2ac8637b29b Mon Sep 17 00:00:00 2001 From: dcog989 <89043002+dcog989@users.noreply.github.com> Date: Mon, 14 Apr 2025 11:20:55 +0100 Subject: [PATCH] Fix Color Picker resource leak (#38122) (#38147) * Fix Color Picker resource leak (#38122) Added a using statement to properly dispose of the Graphics object created from the Bitmap. This fixes resource leak. * Fix CI complain * Update MouseInfoProvider.cs fix whitespace --------- Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com> --- .../colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs index 76c376b761..c28dcc1ae6 100644 --- a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs +++ b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs @@ -104,8 +104,10 @@ namespace ColorPicker.Mouse var rect = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1); using (var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb)) { - var g = Graphics.FromImage(bmp); - g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy); + using (var g = Graphics.FromImage(bmp)) // Ensure Graphics object is disposed + { + g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy); + } return bmp.GetPixel(0, 0); }