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;
}
}
(2) 释放时先判空(记得变量要初始化)
以下为目前认为比较好的方式:
for (std::vector<GGJCustomBarLineEntity*>::iterator itr = m_vecEntityList.begin();
m_vecEntityList.end() != itr; ++itr)
{
if (nullptr != (*itr))
{
delete (*itr);
(*itr) = nullptr;
}
}
相关文章推荐
- c++ 对象内存释放
- C++对象数组释放时的非故意内存泄露
- C++中单例对象的内存自动释放
- C++基类指针指向的派生类对象内存的释放
- 关于C++中结构体及其指针成员的内存分配和释放
- C++对象内存布局--⑤GCC编译器--单个虚拟继承
- c++对象内存模型【内存布局】
- C++内存对象大会战
- 以C++为例子,通过操作内存模拟实现对象的持久化存储(一)
- 三十二、C++内存布局,对象大小计算、虚函数虚继承对类内存模型的影响
- C++ 对象的内存布局(上)
- 浅谈C++中派生类对象的内存布局
- C++内存对象大会战 禁止产生堆对象 禁止产生栈对象
- C++ 对象的内存布局(上)
- C++面向对象编程:对象的内存分配与静态成员
- c与c++分别是怎样动态分配和释放内存的,有什么区别?
- C++由于指针对象释放,造成Std::__non_rtti_Object例外发生
- C++内存对象大会战
- C++ 对象的内存布局(下)
- C++-对象继承内存模型配图