読んだ後: C++ ポインターの配列: [] を削除または削除しますか? (shai vashid による返信) および http://www.cplusplus.com/forum/beginner/6651/
私は以下を実装しました:
カーネル.h
unsigned int **ConfigMeM;
//.....
~Kernel(){ //destructor
for (unsigned int i=0; i<MeMSize; i++)
delete [] MeM[i]; //Valgrind:- Invalid read of size 4
- Invalid free() / delete / delete[] / realloc()
delete [] MeM; //Valgrind: Invalid free() / delete / delete[] / realloc()
for (unsigned int i=0; i<_item_tot; i++)
delete [] ConfigMeM[i]; //Valgrind: Same comments as above
delete [] ConfigMeM; //Valgrind: same as above
};
カーネル.cpp
//.......
MeM = new unsigned int*[MeMSize];
for (unsigned int i=0; i<MeMSize; i++){
MeM[i] = new unsigned int[11]; //Valgrind: 14,608 bytes in 332 blocks are definitely lost in loss record 2,021 of 2,036
}
for (unsigned int i=0; i<MeMSize; i++){
for (int j=0; j<10; j++){
MeM[i][j] = 0;
}
}
//.....
ConfigMeM = new unsigned int*[_item_tot];
for (unsigned int i=0; i<_item_tot; i++){
ConfigMeM[i] = new unsigned int[3]; //Valgrind: 1,200 bytes in 100 blocks are definitely lost in loss record 1,131 of 2,036
}
for (unsigned int i=0; i<_item_tot; i++){
for (int j=0; j<3; j++){
ConfigMeM[i][j] = 0;
}
}
//.....
何が間違っているのかわかりません。
何か提案はありますか?
ありがとうございました。