您的位置:首页 > 编程语言 > C语言/C++

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

2015-04-27 12:14 211 查看
(1)迭代器优于下标的方式

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

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

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

m_vecEntityList.end() != itr; ++itr)

{

if (nullptr != (*itr))

{

delete (*itr);

(*itr) = nullptr;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: