私はこの2D Qlistを作成しました。コードは機能しますが、シンタックスを少し深く考えてみると、このコードがメモリリークを引き起こすかどうかはわかりません。2d QListメモリリーク
誰かがこのコードがmemのリークにつながるかどうかを明らかにすることができたら嬉しいです。それがあれば、なぜ、どのように修正するのですか?
私の懸念事項は、コードコメントでQ1、Q2、Q3、Q4とマークされている質問です。
また、どのようにlszq2DListからいくつかの行を破壊する必要があります。最終的にどのように破壊するべきですか? lszq2DList
//The 2d data sructure. Each row will be a QStringList.
QList<QStringList> lszq2DList;
//The variable "emptyTempList" is a concern to me.
//Q1:: Isn't "emptyTempList" just a pointer to some allocated place in memory?
//If so, I imagine it points to some data structure allocated in memory.
//Or does this not allocate anything? I have a feeling it does not.
QStringList emptyTempList; //I use it in my scheme to make a 2D data struct.
for(int i=0; i<3; i++){
//Q2: Because I am in a loop and reusing the same pointer "emptyTempList",
//aren't i pointing to the same thing?
//If I think about this, each item in my Qlist (each row) should be
//pointing to the same place in memory. To whatever "emptyTempList"
//points to.
//Of course, this is not the case. What is really going on in line bellow?
lszq2DList += emptyTempList; //I'm no really pointing to anything am I?
QString szqTempString; //Q3: Gets trashed when out of scope?
for(int j=0; j<3; j++){
szqTempString.clear();
szqTempString = "jazz";
//QString value gets copied into datastructure?
lszq2DList[i] += szqTempString;
}
}
QStringList emptyTempList2;
emptyTempList2 += "blues";
emptyTempList2 += "blues";
emptyTempList2 += "blues";
//I'll add another row.
lszq2DList += emptyTempList2;
//Q4: lszq2DList[3] does not point to emptyTempList2, right?
//Instead it copies all the strings
//from to emptyTempList2 to lszq2DList[3], right?
投稿されたコードにはメモリ割り当てもありません。どのように漏れがありますか? –