Memory issues (and leaks) in build 203

 
Hi MetaQuotes,
Here is a very simple code (implemented as indicator) which heavily increases the computer's memory consumption. I only calls the iTime function in a loop.
Can you tell me what the problem is?
Thanks
Ruby

#property indicator_separate_window
#property indicator_buffers 0
	   
string symbols[6];
int timeframes[6];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
void init()
{
   symbols[0] = "EURUSD";
   symbols[1] = "USDJPY";
   symbols[2] = "GBPUSD";
   symbols[3] = "USDCHF";
   symbols[4] = "GBPJPY";
   symbols[5] = "USDCAD";
   
   timeframes[0] = PERIOD_M1;
   timeframes[1] = PERIOD_M5;
   timeframes[2] = PERIOD_M15;
   timeframes[3] = PERIOD_M30;
   timeframes[4] = PERIOD_H1;
   timeframes[5] = PERIOD_H4;
}
	   
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
int start()
{
   for (int i = 0; i < ArraySize(symbols); i++)
   {
      for (int j = 0; j < ArraySize(timeframes); j++)
      {
         iTime(symbols[i], timeframes[j], 0);
      }
   }
   
   return (0);
}


 
Of course increases. All requested historical data saved in the memory until release with EA/custom indicator/script unload.

There are no memory leaks.
 
Of course increases. All requested historical data saved in the memory until release with EA/custom indicator/script unload.

There are no memory leaks.


Thanks Slawa,
Even when removing the indicator, the memory doesn't get back to it's initial state.
Besides, this data saved in memory for what purpuse?
Ruby
 
Of course increases. All requested historical data saved in the memory until release with EA/custom indicator/script unload.
There are no memory leaks.


Slawa,
Sorry, but please check out the attached code.
It seems like a memory leak / bug.
I'm using a local variable t to keep the iTime function value, and still the memory is going higher just up as before.
Thanks again,
Ruby

#property indicator_separate_window
#property indicator_buffers 0
	   
string symbols[6];
int timeframes[6];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
void init()
{
   symbols[0] = "EURUSD";
   symbols[1] = "USDJPY";
   symbols[2] = "GBPUSD";
   symbols[3] = "USDCHF";
   symbols[4] = "GBPJPY";
   symbols[5] = "USDCAD";
   
   timeframes[0] = PERIOD_M1;
   timeframes[1] = PERIOD_M5;
   timeframes[2] = PERIOD_M15;
   timeframes[3] = PERIOD_M30;
   timeframes[4] = PERIOD_H1;
   timeframes[5] = PERIOD_H4;
}
	   
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
int start()
{
   datetime t;
   for (int i = 0; i < ArraySize(symbols); i++)
   {
      for (int j = 0; j < ArraySize(timeframes); j++)
      {
         t = iTime(symbols[i], timeframes[j], 0);
      }
   }
   
   return (0);
}


 
Even when removing the indicator, the memory doesn't get back to it's initial state.
Besides, this data saved in memory for what purpuse?

Released in 5 minutes after EA/indicator/script unload.
Information saved in memory for next possible requests
 
Slawa,
From MT4 help:
Local variables are stored in memory area of the corresponding function.


Why this code doesn't free memory? I'm using a local variable.

int start()
{
   datetime t;
   for (int i = 0; i < ArraySize(symbols); i++)
   {
      for (int j = 0; j < ArraySize(timeframes); j++)
      {
         t = iTime(symbols[i], timeframes[j], 0);
      }
   }
   
   return (0);
}
 
You call iTime function therefore You request for the all accessible data (max bars in the chart) of the appropriate symbol-timeframe
 
You call iTime function therefore You request for the all accessible data (max bars in the chart) of the appropriate symbol-timeframe


1. Does the same happen when calling iBars, iCustom, etc. (all "i" functions)?
2. Is there a workaround to programmatically free unused memory (garbage collection)?
 
Slawa,
I've just checked it in build 201 and it behaves much better.
 
1. Yes
2. No
 
Slawa,
I've just checked it in build 201 and it behaves much better.

Compare bars count on the chart