Note that there are some explanatory texts on larger screens.

plurals
  1. PO2d QList Memory Leak
    primarykey
    data
    text
    <p>I created this 2D Qlist. Code "works" but when I consider a bit deeper the syntax it leaves me wondering whether this code leads to memory leak. </p> <p>I would be great if someone could shed some light on whether this code leads to a mem leak or not. If it does, WHY and how to fix? </p> <p>My Specific concerns are question marked as Q1,Q2,Q3,Q4 in code comments.</p> <p>Also, how should I destroy some rows from lszq2DList and ultimately how should I destroy lszq2DList.</p> <pre><code>//The 2d data sructure. Each row will be a QStringList. QList&lt;QStringList&gt; 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&lt;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&lt;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? </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload