c++ - icu RegexMatcher 内存未释放

标签 c++ regex icu

当我使用 RegexMatcher(来自 icu api)时,内存没有被释放。 完成重置后内存未被释放,每次重置都会导致更多内存丢失(inputBuffer 是 UnicodeString)。

似乎只是创建一个新的 RegexMatcher 对象然后删除它会泄漏内存...

请问我遗漏了什么?

UErrorCode matcherStatus = U_ZERO_ERROR;
RegexMatcher * lastWordMatcher = new RegexMatcher(".*(^|\\p{Z})(\\S+)$", UREGEX_ERROR_ON_UNKNOWN_ESCAPES | UREGEX_UWORD, matcherStatus);

UnicodeString lastWord;

lastWordMatcher->reset(inputBuffer);
if (lastWordMatcher->find(matcherStatus))
{
    lastWord = lastWordMatcher->group(2, matcherStatus);
}
delete lastWordFinder;

最佳答案

隐藏在 icu 文档中的是这个评论

When an application is terminating, it may optionally call the function u_cleanup(void) , which will free any heap storage that has been allocated and held by the ICU library. The main benefit of u_cleanup() occurs when using memory leak checking tools while debugging or testing an application. Without u_cleanup(), memory being held by the ICU library will be reported as leaks.

关于c++ - icu RegexMatcher 内存未释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42044178/

相关文章:

ICU 相当于 strerror(3) 用于获取 UErrorCode 的消息?

c++ - cout 同步关闭时的速度

regex - Vim 正则表达式反向引用

java - ICU 音译片假名过滤器不适用于半角片假名浊音标记

python - 如何在 Python 中找到与正则表达式的所有匹配项?

ruby - 使用正则表达式、变量和字符串将文件复制到新文件 gsub 时出现问题吗?

c++ - utext_openUTF8 返回字符串 "mod-12k"的错误;

c++ - 为什么这些重载函数调用不明确?

c++ - 我如何静态断言 numeric_limits::max()?

c++ - 为什么父进程的输出被子进程阻塞?