c++ - STL容器泄漏

标签 c++ windows winapi stl

我正在使用 vector 容器来保存包含 3 个整数和 2 个 std::string 的对象的实例,这是在堆栈上创建的并从另一个类中的函数填充但是通过 deleaker 运行应用程序显示对象中的 std::string 全部泄漏。这是代码:

// Populator function:
void PopulatorClass::populate(std::vector<MyClass>& list) {
    // m_MainList contains a list of pointers to the master objects
    for( std::vector<MyClass*>::iterator it = m_MainList.begin(); it != m_MainList.end(); it++ ) {
        list.push_back(**it);
    }
}

// Class definition
class MyClass {
private:
    std::string m_Name;
    std::string m_Description;
    int m_nType;
    int m_nCategory;
    int m_nSubCategory;
};

// Code causing the problem:
std::vector<MyClass> list;
PopulatorClass.populate(list);

当它通过 deleaker 运行时,泄漏的内存位于 std::string 类的分配器中。

我使用的是 Visual Studio 2010 (CRT)。

在展开堆栈和删除 vector 时,我需要做些什么才能正确删除 string 吗?

谢谢, J

最佳答案

可能是Memory leak with std::vector<std::string> 或类似的东西。

关于c++ - STL容器泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4494012/

相关文章:

c++ - 如何逐个添加两个 STL vector 的元素?

c++ - 接收 HTTP 多部分流时 libCURL 超时

python - .py转.exe,三个问题

java - 使用 JNA 获取正在运行的进程

c - 没有收到 WM_DISPLAYCHANGE

c++ - 为什么我的链表实现不起作用?

c++ - 使用 pantheios 从多个进程并发写入日志文件

windows - 如何创建启动 Cygwin 并跟踪特定文件的桌面快捷方式?

java - 在未安装 JRE 的情况下在 Windows 中将 java 程序作为 exe 运行

c - 如何在win32静态控件中添加文本到现有文本