2012-11-18 101 views
-1

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; 
} 

任何幫助,將不勝感激。我一直在這上好幾個小時,我討厭不乾淨的代碼...

+0

什麼是HS :: H5File?你可以展示什麼是dsMean.getSpace.getSimpleExtentDims定義的定義? – dchhetri

+0

我們需要更多的代碼。 'H5 :: DataSpace :: getSpace()'真的做了什麼? – Synxis

+0

對不起,我認爲這很明顯,但顯然不是。這些是來自HDF5庫的C++接口的函數。它是這樣的:http://www.hdfgroup.org/HDF5/doc/cpplus_RM/classH5_1_1DataSet.html getSpace()返回DataSpace的副本,我可以從中獲取數據的維度。 – Ela782

回答

0

使用H5::DataSet::vlenReclaim在完成使用後回收內存。

+0

嗯我已經看過這個現在,我必須說我不是很明白。我可以找到的唯一遠程有用的東西是http://www.hdfgroup.org/ftp/HDF5/current/src/unpacked/c++/test/tvlstr.cpp,但我現在知道發生了什麼以及如何使用它我更簡單的代碼。 – Ela782

+0

我仍然無法解決此問題或瞭解該示例。任何額外的幫助將受到我的歡迎。 – Ela782

0

可變長度回收僅適用於使用可變長度數據類型的情況,我認爲您不會在本例中使用這種可變長度數據類型。我想你只需在完成使用後關閉數據空間。