Fixed memory leak when running Tesseract

This commit is contained in:
niksedk 2014-03-27 20:39:25 +01:00
parent 6016d501e4
commit dee073450a

View File

@ -214,18 +214,17 @@ namespace Nikse.SubtitleEdit.Forms
int _selectedIndex = -1; int _selectedIndex = -1;
VobSubOcrSettings _vobSubOcrSettings; VobSubOcrSettings _vobSubOcrSettings;
bool _italicCheckedLast; bool _italicCheckedLast;
bool _useNewSubIdxCode;
double _unItalicFactor = 0.33; double _unItalicFactor = 0.33;
BinaryOcrDb _binaryOcrDb = null; BinaryOcrDb _binaryOcrDb;
string _binaryOcrDbFileName = null; string _binaryOcrDbFileName;
int _binOcrLastLowercaseHeight = -1; int _binOcrLastLowercaseHeight = -1;
int _binOcrLastUppercaseHeight = -1; int _binOcrLastUppercaseHeight = -1;
Timer _mainOcrTimer; Timer _mainOcrTimer;
int _mainOcrTimerMax = 0; int _mainOcrTimerMax;
int _mainOcrIndex = 0; int _mainOcrIndex;
bool _mainOcrRunning = false; bool _mainOcrRunning = false;
Bitmap _mainOcrBitmap= null; Bitmap _mainOcrBitmap= null;
@ -239,8 +238,8 @@ namespace Nikse.SubtitleEdit.Forms
List<Color> _palette; List<Color> _palette;
// BluRay sup // BluRay sup
List<Nikse.SubtitleEdit.Logic.BluRaySup.BluRaySupParser.PcsData> _bluRaySubtitlesOriginal; List<Logic.BluRaySup.BluRaySupParser.PcsData> _bluRaySubtitlesOriginal;
List<Nikse.SubtitleEdit.Logic.BluRaySup.BluRaySupParser.PcsData> _bluRaySubtitles; List<Logic.BluRaySup.BluRaySupParser.PcsData> _bluRaySubtitles;
// SP list // SP list
List<SpHeader> _spList; List<SpHeader> _spList;
@ -285,9 +284,9 @@ namespace Nikse.SubtitleEdit.Forms
bool _icThreadsStop = false; bool _icThreadsStop = false;
string[] _icThreadResults = null; string[] _icThreadResults = null;
Keys _italicShortcut = Utilities.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxItalic); readonly Keys _italicShortcut = Utilities.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxItalic);
Keys _mainGeneralGoToNextSubtitle = Utilities.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToNextSubtitle); readonly Keys _mainGeneralGoToNextSubtitle = Utilities.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToNextSubtitle);
Keys _mainGeneralGoToPrevSubtitle = Utilities.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToPrevSubtitle); readonly Keys _mainGeneralGoToPrevSubtitle = Utilities.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToPrevSubtitle);
private string[] _tesseractAsyncStrings = null; private string[] _tesseractAsyncStrings = null;
private int _tesseractAsyncIndex = 0; private int _tesseractAsyncIndex = 0;
@ -591,7 +590,6 @@ namespace Nikse.SubtitleEdit.Forms
internal bool Initialize(string vobSubFileName, VobSubOcrSettings vobSubOcrSettings, bool useNewSubIdxCode, Main main) internal bool Initialize(string vobSubFileName, VobSubOcrSettings vobSubOcrSettings, bool useNewSubIdxCode, Main main)
{ {
_main = main; _main = main;
_useNewSubIdxCode = useNewSubIdxCode;
buttonOK.Enabled = false; buttonOK.Enabled = false;
buttonCancel.Enabled = false; buttonCancel.Enabled = false;
buttonStartOcr.Enabled = false; buttonStartOcr.Enabled = false;
@ -992,7 +990,7 @@ namespace Nikse.SubtitleEdit.Forms
languageString = languageString.ToLower(); languageString = languageString.ToLower();
for (int i = 0; i < comboBoxTesseractLanguages.Items.Count; i++) for (int i = 0; i < comboBoxTesseractLanguages.Items.Count; i++)
{ {
TesseractLanguage tl = (comboBoxTesseractLanguages.Items[i] as TesseractLanguage); var tl = (comboBoxTesseractLanguages.Items[i] as TesseractLanguage);
if (tl.Text.StartsWith("Chinese") && (languageString.StartsWith("chinese") || languageString.StartsWith("中文"))) if (tl.Text.StartsWith("Chinese") && (languageString.StartsWith("chinese") || languageString.StartsWith("中文")))
{ {
comboBoxTesseractLanguages.SelectedIndex = i; comboBoxTesseractLanguages.SelectedIndex = i;
@ -5379,11 +5377,15 @@ namespace Nikse.SubtitleEdit.Forms
void TesseractThreadDoWork(object sender, DoWorkEventArgs e) void TesseractThreadDoWork(object sender, DoWorkEventArgs e)
{ {
var bitmap = (Bitmap)e.Argument; var bitmap = (Bitmap)e.Argument;
if (bitmap != null)
{
if (_tesseractAsyncIndex >= 0 && _tesseractAsyncIndex < _tesseractAsyncStrings.Length) if (_tesseractAsyncIndex >= 0 && _tesseractAsyncIndex < _tesseractAsyncStrings.Length)
{ {
if (string.IsNullOrEmpty(_tesseractAsyncStrings[_tesseractAsyncIndex]) && bitmap != null) if (string.IsNullOrEmpty(_tesseractAsyncStrings[_tesseractAsyncIndex]))
_tesseractAsyncStrings[_tesseractAsyncIndex] = Tesseract3DoOcrViaExe(bitmap, _languageId, "-psm 6"); // 6 = Assume a single uniform block of text.); _tesseractAsyncStrings[_tesseractAsyncIndex] = Tesseract3DoOcrViaExe(bitmap, _languageId, "-psm 6"); // 6 = Assume a single uniform block of text.);
} }
bitmap.Dispose();
}
} }
void TesseractThreadRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) void TesseractThreadRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
@ -7702,7 +7704,6 @@ namespace Nikse.SubtitleEdit.Forms
internal void Initialize(string fileName, List<Color> palette, VobSubOcrSettings vobSubOcrSettings, List<SpHeader> spList) internal void Initialize(string fileName, List<Color> palette, VobSubOcrSettings vobSubOcrSettings, List<SpHeader> spList)
{ {
_spList = spList; _spList = spList;
_useNewSubIdxCode = false;
buttonOK.Enabled = false; buttonOK.Enabled = false;
buttonCancel.Enabled = false; buttonCancel.Enabled = false;
buttonStartOcr.Enabled = false; buttonStartOcr.Enabled = false;
@ -7768,7 +7769,6 @@ namespace Nikse.SubtitleEdit.Forms
{ {
_mp4List = subPicturesWithTimeCodes; _mp4List = subPicturesWithTimeCodes;
_useNewSubIdxCode = false;
buttonOK.Enabled = false; buttonOK.Enabled = false;
buttonCancel.Enabled = false; buttonCancel.Enabled = false;
buttonStartOcr.Enabled = false; buttonStartOcr.Enabled = false;
@ -7807,7 +7807,6 @@ namespace Nikse.SubtitleEdit.Forms
{ {
_xSubList = subPictures; _xSubList = subPictures;
_useNewSubIdxCode = false;
buttonOK.Enabled = false; buttonOK.Enabled = false;
buttonCancel.Enabled = false; buttonCancel.Enabled = false;
buttonStartOcr.Enabled = false; buttonStartOcr.Enabled = false;