c++ - boost::regex 库中的内存泄漏

标签 c++ windows boost memory-leaks mfc

我不太喜欢 Boost 库。我需要它来匹配我在 VS 2008 中编译的遗留 C++/MFC 项目中的正则表达式。

这是一个简短的代码片段:

//Need Unicode support
CString ss;
boost::tregex r(L"<(From )?([A-Za-z0-9_]+)>(.*?)");
boost::tmatch what;
CString chat_input(L"<Darker> Hello");
if(boost::regex_match(chat_input, what, r))     //Memory leak on this line
{
    // extract $1 as a CString:
    ss = L"Match";//CString(what[1].first, what.length(1));
}
else
{
    ss = L"No match";
}

当我在 Debug模式下运行它时,我在输出窗口中得到以下内容:

Detected memory leaks!
Dumping objects ->
{287} normal block at 0x00460068, 4096 bytes long.
 Data: <                > 00 00 00 00 CD CD CD CD CD CD CD CD CD CD CD CD 
Object dump complete.

如果我注释掉 boost::regex_match 行,泄漏就会消失。

我在这里错过了什么?

附言。我链接到的 boost 版本是 1_55_0。

最佳答案

单元测试框架CppUnit ,还提示 boost::regex 库中的“内存泄漏”。

我认为这是因为 boost::regex 实现使用静态成员变量,如“Meyers”单例,内存泄漏检测不喜欢它。 boost 库没有问题,它肯定不是泄漏内存!

在 MSVC 2010 之后,您可以使用 std::regex 代替,我可以向您保证不会报告任何泄漏。在 MSVC 2008 中,您应该能够使用 std::tr1::regex,但很抱歉,我对此没有任何经验。

关于c++ - boost::regex 库中的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20133961/

相关文章:

c++ - 太多的模仿猫我搞不懂

sql - 适用于 Windows 的 Postgres 查询日志记录

c++ - 在 C++ 中删除命名空间 boost

c++ - 使用 cygwin 编译 boost 程序的问题

c++ - basic_string 预期初始化程序编译错误

c++ - 有没有一个工具可以绘制我的 C++ 类和方法的图形表示?

c++ - 使用 SDL 消失的矩形

windows - 在CMD中使用时如何转义密码中的特殊字符

python - Scrapy安装报错pip和easy_install

c++ - boost thread_group 将 unique_ptr 的所有权移动到线程