iBars() memory bomb

 

REF: https://www.mql5.com/en/forum/158112

I do not want to revive the old thread, here, "due to the fact that the terminal stores symbol data for 10 minutes since the last access to them", so 1 single chart with the below code can span ~100MB of RAM depends on how many data are in your terminal, and when you got 28 charts, you'd probably get 2800MB of RAM used by MT4. And you know what, MT4 is a 32-bit application which can only handle at maximum 4GB of RAM, so your MT4 may freeze and drop this expert advisor if bar data are slightly more than me.


Let me share the bomb code :D

//EXPERT ADVISOR
string Allpairs[] =  {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CADJPY", "CHFJPY", "EURAUD", "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNZD", "EURUSD", "GBPAUD", "GBPCAD", "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDCAD", "NZDCHF", "NZDJPY", "NZDUSD", "USDCAD", "USDCHF", "USDJPY"};
ENUM_TIMEFRAMES TF[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1}; //Timeframe

int OnInit(){
  for(int i = 0; i < ArraySize(Allpairs); i++){
    for(int j = 0; j < ArraySize(TF); j++){
      iBars(Allpairs[i], TF[j]);
    }
  }
  return 0;
}
void OnTick(){}

So my question is, how could I release those memory by code, without waiting 10 minutes? Does it even possible?

edit: I can create alert if "Max bar in chart" is too big, but would still want to know if there is true solution on memory release

MT4 Memory Use and Indicators
MT4 Memory Use and Indicators
  • 2016.01.24
  • www.mql5.com
I've got 5 charts open, 200000 bars in chart. MqlRates structure is (7 * 8) + 4 bytes = 60 bytes...
 
  1. There is no release. Read one pair/timeframe, and process. Then move on.

  2. Maximum charts on a terminal is 99. You are trying to read 28 * 9 = 252. Multiple terminals requied.

  3. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 (2019)

 
Yu Pang Chan:

REF: https://www.mql5.com/en/forum/158112

I do not want to revive the old thread, here, "due to the fact that the terminal stores symbol data for 10 minutes since the last access to them", so 1 single chart with the below code can span ~100MB of RAM depends on how many data are in your terminal, and when you got 28 charts, you'd probably get 2800MB of RAM used by MT4. And you know what, MT4 is a 32-bit application which can only handle at maximum 4GB of RAM, so your MT4 may freeze and drop this expert advisor if bar data are slightly more than me.


Let me share the bomb code :D


So my question is, how could I release those memory by code, without waiting 10 minutes? Does it even possible?

edit: I can create alert if "Max bar in chart" is too big, but would still want to know if there is true solution on memory release

Why do you need this?. Calculate the value as you trade. Loading into memory in init is of no use. This way the calculation will be wrong. With "iBarShift" you can do whatever you want to do at the moment of operation. You cannot find the 1st bar in PERIOD_M1 and the 1st bar in PERIOD_M30 this way. Since I don't know what you're doing, this code apparently just bloats the memory.

Reason: