C++最好的释放对象内存

来源:互联网 发布:openwrt 修改mac地址 编辑:程序博客网 时间:2024/04/29 21:38

(1)迭代器优于下标的方式

(2)   释放时先判空(记得变量要初始化)


以下为目前认为比较好的方式:

 for (std::vector<GGJCustomBarLineEntity*>::iterator itr = m_vecEntityList.begin();

        m_vecEntityList.end() != itr; ++itr)
    {
        if (nullptr != (*itr))
        {
            delete (*itr);
            (*itr) = nullptr;
        }

    }



0 0
原创粉丝点击