Refactor redundant Dispose calls into a single method

Reorganized the way various graphics disposal were handled in the LayoutPicker form. Instead of individual dispose calls, the disposing logic has been consolidated into a new method named DisposeGraphics(). This makes our disposal logic more modular, maintainable, and easier to read.

Signed-off-by: Ivandro Jao <ivandrofly@gmail.com>
This commit is contained in:
Ivandro Jao 2024-06-27 16:45:37 +01:00
parent 759b6fcaa8
commit 5206edfd5e

View File

@ -46,18 +46,7 @@ namespace Nikse.SubtitleEdit.Forms
private void UpdateButtons(int initialLayout)
{
_gray1?.Dispose();
_gray2?.Dispose();
_gray3?.Dispose();
_gray4?.Dispose();
_gray5?.Dispose();
_gray6?.Dispose();
_gray7?.Dispose();
_gray8?.Dispose();
_gray9?.Dispose();
_gray10?.Dispose();
_gray11?.Dispose();
_gray12?.Dispose();
DisposeGraphics();
_gray1 = GrayScale(Properties.Resources.L1, initialLayout == 0);
_gray2 = GrayScale(Properties.Resources.L2, initialLayout == 1);
@ -536,6 +525,22 @@ namespace Nikse.SubtitleEdit.Forms
ShowVideoControls = checkBoxHideVideoControls.Checked;
}
private void DisposeGraphics()
{
_gray1?.Dispose();
_gray2?.Dispose();
_gray3?.Dispose();
_gray4?.Dispose();
_gray5?.Dispose();
_gray6?.Dispose();
_gray7?.Dispose();
_gray8?.Dispose();
_gray9?.Dispose();
_gray10?.Dispose();
_gray11?.Dispose();
_gray12?.Dispose();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
@ -544,18 +549,7 @@ namespace Nikse.SubtitleEdit.Forms
{
if (disposing)
{
_gray1?.Dispose();
_gray2?.Dispose();
_gray3?.Dispose();
_gray4?.Dispose();
_gray5?.Dispose();
_gray6?.Dispose();
_gray7?.Dispose();
_gray8?.Dispose();
_gray9?.Dispose();
_gray10?.Dispose();
_gray11?.Dispose();
_gray12?.Dispose();
DisposeGraphics();
components?.Dispose();
}