iphone - 使用 Tesseract 进行 OCR 会导致 GetUTF8Text 方法出现内存泄漏

标签 iphone c++ ios ocr tesseract

我正在使用 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 文件中。我认为 tessearact 是由 c++ 编写的。我不知道 C++。 谁能帮忙?或者有人有干净的 tesseract 吗?

最佳答案

根据我在 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();

因此,您需要在完成后删除[] utf8text

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

关于iphone - 使用 Tesseract 进行 OCR 会导致 GetUTF8Text 方法出现内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10806491/

相关文章:

iphone - 我想通过我们的应用程序在 "EverNote"中存储一些数据

c++ - OpenGL 深度无法按预期工作

c++ - C++ 数据结构对象的生命周期是多少?

ios - Firebase 身份验证 token ,检查是否有效

iphone - 从 xcode 项目中删除不必要的图像

android - 如何让用户一次只能从一台设备登录

iOS 7 Storyboard调试建议

ios - Swift 泛型和协议(protocol)

iphone - 从 UITableView1 导航到 UITableView2 时应显示事件指示器

C++ 内置交换两个数值?