CArray and Clear function

To add comments, please log in or register
HarriMQL5
330
HarriMQL5  

The documentation for the Clear function states:

"Deletes all of the array elements without memory release."

So does that mean I will get memory leaks using this function? I am actually using CArrayDouble, derived from CArray.

Thank you.

Anthony Garot
1818
Anthony Garot  
HarriMQL5:

The documentation for the Clear function states:

"Deletes all of the array elements without memory release."

So does that mean I will get memory leaks using this function? I am actually using CArrayDouble, derived from CArray.

Thank you.

If you look at the code for CArray's Clear() method, you see:

void              Clear(void) { m_data_total=0; }

So, all the memory that had been allocated is still allocated; it simply resets the counter to 0.

Will you get memory leaks? Not if you delete your instance of the CArrayDouble you created. See the last line of the example code here:

https://www.mql5.com/en/docs/standardlibrary/datastructures/carray/carrayclear

Inside the CArrayDouble instance you create is a protected array called m_data[]. When you delete your instance of CArrayDouble and this array is released.

To add comments, please log in or register