JWo*_*ood 1 c++ windows winapi stl
我正在使用向量容器来保存包含3个int和2个std::strings 的对象的实例,这是在堆栈上创建并从另一个类中的函数填充但是通过deleaker运行应用程序显示std::string来自对象的s都是泄露.这是代码:
// 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);
Run Code Online (Sandbox Code Playgroud)
当通过deleaker运行时,泄漏的内存位于std::string类的分配器中.
我正在使用Visual Studio 2010(CRT).
string在展开堆栈并删除vector?时,我需要做些什么特别的事情才能正确删除?
谢谢,J
| 归档时间: |
|
| 查看次数: |
1894 次 |
| 最近记录: |