小编Abh*_*Sen的帖子

内存泄漏与地图

我无法清除地图内存(我通过Valgrind检查).

#include <map>

class testMap {
    public:
        testMap(){}
        ~testMap();

        void insert_map(int, int);

    private:
          std::map<int,int> _map;
};

void testMap::insert_map(int i, int j){
    _map.insert( pair<int, int>(i,j));
}
Run Code Online (Sandbox Code Playgroud)

我试过_map.clear(),手动erase()删除_map->second但不是没有运气.


感谢所有回复.实际上map一个人不是问题,但是map单身人士会导致泄密.下面的代码有什么问题?

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include "Object.h"

#include<boost/smart_ptr.hpp>

using namespace std;

class Singleton {
    public:

        // A wrapper around Object class
        class object
        {
            public:
                object() : _object(new Object())
                    {}
                Object get(void)
                    { return _object.get(); }
            private:
                boost::shared_ptr<Object> …
Run Code Online (Sandbox Code Playgroud)

c++ memory-leaks map

5
推荐指数
2
解决办法
7129
查看次数

标签 统计

c++ ×1

map ×1

memory-leaks ×1