C++ 泄漏的c++;xcode中的列表 经度=d;
虽然我添加了一个解构器来移除所有对象,但这里似乎有泄漏:C++ 泄漏的c++;xcode中的列表 经度=d;,c++,xcode,list,memory-leaks,C++,Xcode,List,Memory Leaks,虽然我添加了一个解构器来移除所有对象,但这里似乎有泄漏: for(std::list<SRComplexType>::iterator list_iter = refs.begin(); list_iter != refs.end(); list_iter++) { list_iter->~SRComplexType(); } sLocation(仅包含两个Double和一些方法)通过以下方式设置: this->sLocation = new Locat
for(std::list<SRComplexType>::iterator list_iter = refs.begin();
list_iter != refs.end(); list_iter++)
{
list_iter->~SRComplexType();
}
sLocation(仅包含两个Double和一些方法)通过以下方式设置:
this->sLocation = new LocationComplexType(locationObject);
LocationComplexType中的双精度设置使用:
double d;
const char * str = LatRaw.convert<string>().c_str();
sscanf(str, "%*[^0-9]%lf",&d);
free ((void*) str);
this->longitude=d;
double-d;
const char*str=LatRaw.convert().c_str();
sscanf(str,%*[^0-9]%lf“,&d);
自由((void*)str);
这->经度=d;
仪表泄漏报告给出:
Leaked Object # Address Size Responsible Library Responsible Frame
Malloc < varying sizes > 17 < multiple > 384 Bytes libstdc++.6.dylib std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&)
Malloc 32 Bytes 17 < multiple > 544 Bytes PocoTest2 std::list<SRComplexType, std::allocator<SRComplexType> >::_M_create_node(SRComplexType const&)
Malloc 16 Bytes 1 0x72f2140 16 Bytes PocoTest2 -[ViewController viewDidLoad]
Malloc 3.00 KB 1 0x7c6ca00 3.00 KB libstdc++.6.dylib std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&)
Malloc < varying sizes > 17 < multiple > 560 Bytes libstdc++.6.dylib std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&)
Malloc 32 Bytes 17 < multiple > 544 Bytes libstdc++.6.dylib std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&)
泄漏对象#地址大小负责库负责帧
Malloc17384字节libstdc++.6.dylib std::string::_Rep::_S_create(无符号长、无符号长、std::分配器常量&)
Malloc 32字节17544字节PocoTest2 std::list:_M_create_node(SRComplexType const&)
Malloc 16字节1 0x72f2140 16字节PocoTest2-[ViewController viewDidLoad]
Malloc 3.00 KB 1 0x7c6ca00 3.00 KB libstdc++.6.dylib std::string::_Rep::_S_create(无符号长、无符号长、std::分配器常量&)
Malloc17560字节libstdc++.6.dylib std::string::_Rep::_S_create(无符号长、无符号长、std::分配器常量&)
Malloc 32字节17544字节libstdc++.6.dylib std::string::_Rep::_S_create(无符号长、无符号长、std::分配器常量&)
您的列表似乎包含SRComplexType
对象,因此这里不需要动态分配。只需传递一个SRComplexType
:
refs.push_front(SRComplexType(object));
也不需要删除列表中的元素
如果动态分配了
SRComplexType
的LocationComplexType
,则必须确保遵循或使用(boost::scoped_ptr
或std::unique_ptr
将是很好的候选者)。看起来您的列表包含SRComplexType
对象,所以这里不需要动态分配。只需传递一个SRComplexType
:
refs.push_front(SRComplexType(object));
也不需要删除列表中的元素
如果动态分配了
SRComplexType
的LocationComplexType
,则必须确保遵循或使用(boost::scoped_ptr
或std::unique_ptr
将是很好的候选项)。这是正确的,但没有解释上述代码泄漏的原因。我会查找SRComplexType
@john中的一个错误。我认为没有足够的信息来了解它泄漏的原因,但是应用我建议的修复方法应该可以修复问题,或者至少缩小问题的范围。谢谢@juanchopanza。泄漏现在减少为:Malloc 32字节17SRComplexType
@john中的一个错误。我认为没有足够的信息来了解它泄漏的原因,但是应用我建议的修复方法应该可以修复问题,或者至少缩小问题的范围。谢谢@juanchopanza。泄漏现在减少到:Malloc 32 Bytes 17delete
或析构函数。@cli\hlt对象一开始不是新的,因此,无需调用delete
或析构函数。