我在应用程序中有泄漏,我已经将我的代码减少到下面,并且每次迭代泄漏大约12kb。我看不到这是否是我的代码问题或者xerces库自身的问题。但看看Perfmon中的私人字节,我只能看到增长和收缩,所以显然是漏了。内存泄漏xerces使用
有人可以请指教什么可能是错用下面的代码,导致它在这样一个令人难以置信的速度?:
(单线程测试程序)
for (int x = 0; x < 1000000; x++){
DataSerializer* ds = new DataSerializer();
ds->test(request);
ds->releasedocument();
ds->destroy_xml_lib();
delete ds;
}
void DataSerializer::test(std::string& request)
{
impl = initialize_impl();
}
DOMImplementation* DataSerializer::initialize_impl()
{
try
{
boost::mutex::scoped_lock init_lock(impl_mtx);
XMLPlatformUtils::Initialize();
return DOMImplementationRegistry::getDOMImplementation(XConv("Core"));
}
catch(const XMLException& toCatch)
{
char *pMsg = XMLString::transcode(toCatch.getMessage());
std::string msg(pMsg);
XMLString::release(&pMsg);
}
return NULL;
}
void DataSerializer::destroy_xml_lib()
{
boost::mutex::scoped_lock terminate_lock (impl_mtx); //is being used in MT app
XMLPlatformUtils::Terminate();
}
void DataSerializer::releasedocument()
{
if (document){
document->release();
document = NULL;
}
}
我不明白泄漏这怎么可能泄漏?我错过了什么?
也许你可以展示更多的源代码?例如,DataSerializer构造函数是怎样的? – 2013-03-20 17:29:06