Visual Studio 向我展示了几个泄漏(几百行),总共超过几 MB。我将其追溯到以下“helloWorld 示例”。如果我注释掉 H5::DataSet.getSpace() 行,泄漏就会消失。
#include "stdafx.h"
#include <iostream>
#include "cpp/H5Cpp.h"
int main(int argc, char *argv[])
{
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // dump leaks at return
H5::H5File myfile;
try {
myfile = H5::H5File("C:\\Users\\yyy\\myfile.h5", H5F_ACC_RDONLY);
}
catch (H5::Exception& e) {
std::string msg( std::string( "Could not open HDF5 file.\n" ) + e.getCDetailMsg() );
throw msg;
}
H5::Group myGroup = myfile.openGroup("/so/me/group");
H5::DataSet myDS = myGroup.openDataSet("./myfloatvec");
hsize_t dims[1];
//myDS.getSpace().getSimpleExtentDims(dims, NULL); // <-- here's the leak
H5::DataSpace dsp = myDS.getSpace(); // The H5::DataSpace seems to leak
dsp.getSimpleExtentDims(dims, NULL);
//dsp.close(); // <-- doesn't help either
std::cout << "Dims: " << dims[0] << std::endl; // <-- Works as expected
return 0;
}
任何帮助,将不胜感激。我已经做了几个小时了,我讨厌不干净的代码......