Build 2085 - Pointer data returned are cleaned after return from a function

 
I dont known the build that broken this, but the code below does not work anymore:

#include <Generic\ArrayList.mqh>

CArrayList<int>* GetList(){
   CArrayList<int> list;
   list.Add(123);
   PrintFormat("inside: %d", list.Count());
   return &list;
}

int OnInit(){
   CArrayList<int> list = GetList();
   PrintFormat("outside: %d", list.Count());

   return(INIT_SUCCEEDED);
}

The console return is:

2019.06.20 19:40:17.413 WIN$N,M1: testing of Experts\PointerNullOutOfScopeTest.ex5 from 2019.06.06 00:00 to 2019.06.07 00:00 started
2019.06.20 19:40:27.710 2019.06.06 00:00:00   inside: 1
2019.06.20 19:40:36.468 2019.06.06 00:00:00   outside: 0
2019.06.20 19:40:51.213 2019.06.06 00:00:00   debugging terminated

On debugging, i notice that the step into line "return &list;" goes to CArrayList constructor. 

It's a language behavior or is a garbage collector MT5 bug?


 
Rafael Caetano Pinto:
I dont known the build that broken this, but the code below does not work anymore:


The console return is:

On debugging, i notice that the step into line "return &list;" goes to CArrayList constructor. 

It's a language behavior or is a garbage collector MT5 bug?


It's normal behaviour.
 

Hi,


i don't wanted to start a new thread for this.

How can I use a CList oder CArrayList and hold the data over time?

When i cant use a CList as global variable and hold the data, then this is just trash.

 
You can do so.

Create a global pointer variable and initialize the object with "new" in OnInit.

Also destroy the Object at OnDeinit using "delete".

Very simple and straight forward.