繁体   English   中英

使用Tesseract进行OCR会在GetUTF8Text方法上造成内存泄漏

[英]Using Tesseract for OCR gives memory leak on GetUTF8Text method

我正在使用tesseract OCR进行名片阅读。 我有内存泄漏,我无法解决它,我不知道如何。

在我的代码中......

tesseract->Recognize(NULL); 
char* utf8Text = tesseract->GetUTF8Text();

GetUTF8Text()方法给出了内存泄漏。 这是内存泄漏仪器的日志:

tesseract::TessBaseAPI::GetUTF8Text()
operator new[](unsigned long) libstdc++.6.dylib
operator new(unsigned long) libstdc++.6.dylib
malloc libsystem_c.dylib

一些内存泄漏后,应用程序崩溃。 GetUTF8Text位于baseapi.h文件中。 我认为tessea是由c ++编写的。 我不知道c ++。 有人可以帮忙吗? 或者任何人都有干净的tesseract?

从Tesseract文档:

识别的文本作为char *返回,编码为UTF8,必须使用delete []运算符释放。

换句话说:你有责任释放记忆,所以它是你的泄漏,而不是Tesseracts。

根据我在baseapi.h中找到的文档。

/**
 * The recognized text is returned as a char* which is coded
 * as UTF8 and must be freed with the delete [] operator.
 */
char* GetUTF8Text();

所以你需要在完成后delete [] utf8text

tesseract->Recognize(NULL); 
char* utf8Text = tesseract->GetUTF8Text();
... //use utf8Text or copy if necessary
delete [] utf8text;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM