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;
}
任何幫助,將不勝感激。我一直在這上好幾個小時,我討厭不乾淨的代碼...
什麼是HS :: H5File?你可以展示什麼是dsMean.getSpace.getSimpleExtentDims定義的定義? – dchhetri
我們需要更多的代碼。 'H5 :: DataSpace :: getSpace()'真的做了什麼? – Synxis
對不起,我認爲這很明顯,但顯然不是。這些是來自HDF5庫的C++接口的函數。它是這樣的:http://www.hdfgroup.org/HDF5/doc/cpplus_RM/classH5_1_1DataSet.html getSpace()返回DataSpace的副本,我可以從中獲取數據的維度。 – Ela782