当我使用 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/