我如何设法在 xcode、c++ 中创建泄漏列表。所以在我的 iOS 项目中,我有一个自定义对象列表,如下所示:
int i=0;
while (rawArr->isObject(i)) {
Object::Ptr object = rawArr->getObject(i);
SRComplexType* sr = new SRComplexType(object);
refs.push_front(*sr);
delete sr;
i++;
}
尽管我添加了一个删除所有对象的解构函数,但似乎这里有一些泄漏:
for(std::list<SRComplexType>::iterator list_iter = refs.begin();
list_iter != refs.end(); list_iter++)
{
list_iter->~SRComplexType();
}
}
SRComplexType 包含:
std::string sNo;
std::string sName;
std::string sUrl;
LocationComplexType *sLocation;
sLocation (仅包含两个双精度数和一些方法)使用以下方式设置:
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;
仪器泄漏报告给出:
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&)