From fc9127e8f72d17860c620fbb5e8116c92cd07a94 Mon Sep 17 00:00:00 2001 From: niksedk Date: Fri, 3 Oct 2014 13:48:13 +0200 Subject: [PATCH] Fixed a few resource leaks --- src/Forms/DvdSubRipChooseLanguage.cs | 13 ++-- src/Forms/Main.cs | 98 +++++++++++++++++----------- src/Forms/VobSubOcr.cs | 32 +++++---- 3 files changed, 88 insertions(+), 55 deletions(-) diff --git a/src/Forms/DvdSubRipChooseLanguage.cs b/src/Forms/DvdSubRipChooseLanguage.cs index 8991cf563..ec71f0c29 100644 --- a/src/Forms/DvdSubRipChooseLanguage.cs +++ b/src/Forms/DvdSubRipChooseLanguage.cs @@ -46,8 +46,8 @@ namespace Nikse.SubtitleEdit.Forms private void FixLargeFonts() { - Graphics graphics = this.CreateGraphics(); - SizeF textSize = graphics.MeasureString(buttonOK.Text, this.Font); + var graphics = CreateGraphics(); + var textSize = graphics.MeasureString(buttonOK.Text, Font); if (textSize.Height > buttonOK.Height - 4) { int newButtonHeight = (int)(textSize.Height + 7 + 0.5); @@ -108,8 +108,8 @@ namespace Nikse.SubtitleEdit.Forms height = height * 95 / 100; } - Bitmap temp = new Bitmap((int)width, (int)height); - using (Graphics g = Graphics.FromImage((Image)temp)) + var temp = new Bitmap((int)width, (int)height); + using (var g = Graphics.FromImage(temp)) g.DrawImage(bmp, 0, 0, (int)width, (int)height); bmp = temp; } @@ -191,9 +191,12 @@ namespace Nikse.SubtitleEdit.Forms var formSubOcr = new VobSubOcr(); formSubOcr.InitializeQuick(subs, _palette, Configuration.Settings.VobSubOcr, SelectedLanguageString); var subtitle = formSubOcr.ReadyVobSubRip(); + formSubOcr.Dispose(); + var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.InitializeFromVobSubOcr(subtitle, new Nikse.SubtitleEdit.Logic.SubtitleFormats.SubRip(), "VOBSUB", "DVD", formSubOcr, SelectedLanguageString); + exportBdnXmlPng.InitializeFromVobSubOcr(subtitle, new Logic.SubtitleFormats.SubRip(), "VOBSUB", "DVD", formSubOcr, SelectedLanguageString); exportBdnXmlPng.ShowDialog(this); + exportBdnXmlPng.Dispose(); } } diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 3ea7c3750..4dcbcd187 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -17450,9 +17450,11 @@ namespace Nikse.SubtitleEdit.Forms private void ToolStripMenuItemExportPngXmlClick(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "BDNXML", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "BDNXML", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } private void TabControlSubtitleSelecting(object sender, TabControlCancelEventArgs e) @@ -17839,16 +17841,20 @@ namespace Nikse.SubtitleEdit.Forms private void BluraySupToolStripMenuItemClick(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "BLURAYSUP", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "BLURAYSUP", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } private void VobSubsubidxToolStripMenuItemClick(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "VOBSUB", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "VOBSUB", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } private void TextBoxListViewTextAlternateKeyUp(object sender, KeyEventArgs e) @@ -18035,9 +18041,11 @@ namespace Nikse.SubtitleEdit.Forms private void AdobeEncoreFabImageScriptToolStripMenuItemClick(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "FAB", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "FAB", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } private void ToolStripMenuItemMergeDialogClick(object sender, EventArgs e) @@ -18160,9 +18168,11 @@ namespace Nikse.SubtitleEdit.Forms private void ToolStripMenuItemImagePerFrameClick(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "IMAGE/FRAME", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "IMAGE/FRAME", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } private void toolStripMenuItemApplyDisplayTimeLimits_Click(object sender, EventArgs e) @@ -18832,16 +18842,20 @@ namespace Nikse.SubtitleEdit.Forms private void DvdStudioProStl_Click(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "STL", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "STL", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } private void toolStripMenuItemPlugins_Click(object sender, EventArgs e) { - var form = new PluginsGet(); - form.ShowDialog(this); - LoadPlugins(); + using (var form = new PluginsGet()) + { + form.ShowDialog(this); + LoadPlugins(); + } } private void toolStripMenuItemUndo_Click(object sender, EventArgs e) @@ -18859,16 +18873,18 @@ namespace Nikse.SubtitleEdit.Forms if (audioVisualizer == null) return; - var form = new SeekSilence(); - if (form.ShowDialog(this) == DialogResult.OK) + using (var form = new SeekSilence()) { - if (form.SeekForward) + if (form.ShowDialog(this) == DialogResult.OK) { - audioVisualizer.FindDataBelowThreshold(form.VolumeBelow, form.SecondsDuration); - } - else - { - audioVisualizer.FindDataBelowThresholdBack(form.VolumeBelow, form.SecondsDuration); + if (form.SeekForward) + { + audioVisualizer.FindDataBelowThreshold(form.VolumeBelow, form.SecondsDuration); + } + else + { + audioVisualizer.FindDataBelowThresholdBack(form.VolumeBelow, form.SecondsDuration); + } } } } @@ -19407,9 +19423,11 @@ namespace Nikse.SubtitleEdit.Forms private void toolStripMenuItemExportFcpIImage_Click(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "FCP", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "FCP", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } private void ToolStripMenuItemNuendoPropertiesClick(object sender, EventArgs e) @@ -19426,9 +19444,11 @@ namespace Nikse.SubtitleEdit.Forms private void toolStripMenuItemDost_Click(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "DOST", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "DOST", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } private void toolStripMenuItemMeasurementConverter_Click(object sender, EventArgs e) @@ -19676,9 +19696,11 @@ namespace Nikse.SubtitleEdit.Forms private void toolStripMenuItemExportDcinemaInteropClick(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "DCINEMA_INTEROP", _fileName, _videoInfo); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "DCINEMA_INTEROP", _fileName, _videoInfo); + exportBdnXmlPng.ShowDialog(this); + } } internal Subtitle UndoFromSpellCheck(Subtitle subtitle) diff --git a/src/Forms/VobSubOcr.cs b/src/Forms/VobSubOcr.cs index eff362e5f..21443008b 100644 --- a/src/Forms/VobSubOcr.cs +++ b/src/Forms/VobSubOcr.cs @@ -8022,23 +8022,29 @@ namespace Nikse.SubtitleEdit.Forms private void vobSubToolStripMenuItem_Click(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "VOBSUB", FileName, this, _importLanguageString); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "VOBSUB", FileName, this, _importLanguageString); + exportBdnXmlPng.ShowDialog(this); + } } private void bluraySupToolStripMenuItem_Click(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "BLURAYSUP", FileName, this, _importLanguageString); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "BLURAYSUP", FileName, this, _importLanguageString); + exportBdnXmlPng.ShowDialog(this); + } } private void bDNXMLToolStripMenuItem_Click(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "BDNXML", FileName, this, _importLanguageString); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "BDNXML", FileName, this, _importLanguageString); + exportBdnXmlPng.ShowDialog(this); + } } private void clearToolStripMenuItem_Click(object sender, EventArgs e) @@ -8163,9 +8169,11 @@ namespace Nikse.SubtitleEdit.Forms private void dOSTToolStripMenuItem_Click(object sender, EventArgs e) { - var exportBdnXmlPng = new ExportPngXml(); - exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "DOST", FileName, this, _importLanguageString); - exportBdnXmlPng.ShowDialog(this); + using (var exportBdnXmlPng = new ExportPngXml()) + { + exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "DOST", FileName, this, _importLanguageString); + exportBdnXmlPng.ShowDialog(this); + } } // TODO: Get language from ts file