MODI 2007 を使用していくつかのマルチページ tiff ファイルを OCR するアプリがあります。いくつかの適切な tiff だけでなく、Windows Picture and Fax Viewer で開くことができないいくつかの tiff を含むディレクトリで開始すると、MODI はそれらの「悪い」tiff の OCR にも失敗することがわかりました。これが発生すると、アプリは MODI がそれらの TIFF を OCR するために使用したメモリを再利用できなくなります。ツールがこれらの「不適切な」TIFF を OCR しようとすると、マシンのメモリが不足し、アプリがクラッシュします。MODIメモリリークを修正すると思われるいくつかのコード修正をWebから試しましたが、これまでのところうまくいきませんでした。OCR を実行する以下のコードの一部を貼り付けます。
StringBuilder strRecText = new StringBuilder(10000);
MODI.Document doc1 = new MODI.Document();
doc1.Create(name);
try
{
doc1.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); // this will ocr all pages of a multi-page tiff file
}
catch (Exception e)
{
doc1.Close(false); // clean up
if (doc1 != null)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(doc1);
doc1 = null;
}
}
MODI.Images images = doc1.Images;
for (int imageCounter = 0; imageCounter < images.Count; imageCounter++)
{
if (imageCounter > 0)
{
if (!noPageBreakFlag)
{
strRecText.Append((char)pageBreakChar);
}
}
MODI.Image image = (MODI.Image)images[imageCounter];
MODI.Layout layout = image.Layout;
strRecText.Append(layout.Text);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
if (layout != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(layout);
layout = null;
}
if (image != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(image);
image = null;
}
}
File.AppendAllText(ocrFile, strRecText.ToString()); // write the OCR file out to disk
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
if (images != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(images);
images = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
doc1.Close(false); // clean up
if (doc1 != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(doc1);
doc1 = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();