Download MetaTrader 5

Idenfity reason for "out of memory"

To add comments, please log in or register
Share links from other resources. Now they have a description.
zubr
172
zubr 2013.08.06 18:55 

Hi,

 

my EA seems to have a memory leak since after a while it crashes with "out of memory".  How can I figure out which statement in my EA consumes memory and does not release it afterwards?

 

In my EM I have a function which is frequently invoked and which contains the following code:

 

MACDHandle=iMACD(_Symbol,period,fast_ema_period,slow_ema_period,signal_period,applied_price);

   ArraySetAsSeries( MACDValue,true );     // Set the MACD to timeseries, 0 is the oldest. 

   if( CopyBuffer( MACDHandle,0,0,5,MACDValue ) > 0 ) // Copy value of MACD to MACDValue

      {

            MACDReturnValue = MACDValue[0]; // Print the value of the MACD

          ...

} 

 

May it be possible that memory is lost here? If so, how can I release it again?

Best,

Chris 

Pasi Hakamaki
4677
Pasi Hakamaki 2013.08.06 20:25  
zubr:

Hi,

 

my EA seems to have a memory leak since after a while it crashes with "out of memory".  How can I figure out which statement in my EA consumes memory and does not release it afterwards?

 

In my EM I have a function which is frequently invoked and which contains the following code:

 

 

May it be possible that memory is lost here? If so, how can I release it again?

Best,

Chris 

Hi, This sounds similar to this: https://www.mql5.com/en/forum/12809

So I believe that it might be caused by a bug if you are releasing the indicator handle somewhere in your code. If you are maybe you could try to remove this process from your code and see if that helps :)

Candles

Re-initialization of an indicator
Re-initialization of an indicator
  • www.mql5.com
Do I have to, or can I manually not only release the indicator, but also the memory it used?
zubr
172
zubr 2013.08.06 21:50  
Candles:

Hi, This sounds similar to this: https://www.mql5.com/en/forum/12809

So I believe that it might be caused by a bug if you are releasing the indicator handle somewhere in your code. If you are maybe you could try to remove this process from your code and see if that helps :)

Candles

I did some more debuggin. My problem is the following code that is inside a frequently invoked function:

 

   double high[];
   double low[];
   
   int copiedDataCountHigh = CopyHigh(currentSym, InpPeriod, 0, DonchianPeriod, high);
   int copiedDataCountLow = CopyLow(currentSym, InpPeriod, 0, DonchianPeriod, low);

 When I remove the invocation of CopyHigh and CopyLow than I have no "out of memory" errors. 

Is there a problem with non-released memory? If so, how can I release it? I tried ArrayFree() but this did not work. 

enbo lu
Moderator
1943
enbo lu 2013.08.07 01:54  

Try to limit the array size of high[]/low[]:

   double high[1000];
   double low[1000];
   
   int copiedDataCountHigh = CopyHigh(currentSym, InpPeriod, 0, DonchianPeriod, high);
   int copiedDataCountLow = CopyLow(currentSym, InpPeriod, 0, DonchianPeriod, low);
zubr
172
zubr 2013.08.07 09:07  
luenbo:

Try to limit the array size of high[]/low[]:

This does not help. Even if I limit the array size to 20, I get "out of memory" after a while.
Clock
1183
Clock 2013.08.07 09:29  

This really sounds related to my problem that Candles mentioned earlier on.

So far the service desk status is "we reproduced it and are working on it".

Hopefully, once the solve this issue, both of our problems are gone.

Alain Verleyen
Moderator
30707
Alain Verleyen 2013.08.07 10:26  
Clock:

This really sounds related to my problem that Candles mentioned earlier on.

So far the service desk status is "we reproduced it and are working on it".

Hopefully, once the solve this issue, both of our problems are gone.

This problem seems different, your "bug" is with IndicatorRelease().
Alain Verleyen
Moderator
30707
Alain Verleyen 2013.08.07 10:27  
zubr:
This does not help. Even if I limit the array size to 20, I get "out of memory" after a while.
Can you post a code that compiles and reproduce your issue ?
zubr
172
zubr 2013.08.07 12:11  
angevoyageur:
Can you post a code that compiles and reproduce your issue ?

This is the code in short resulting after approx. 6 min running to an out of memory:

 

input int DonchianPeriod=20;            //Period of averaging
input ENUM_TIMEFRAMES InpPeriod=PERIOD_D1; // Period
string currentSymbol;

int OnInit()
  {
   while(true) {
   for(int i = 0; i < SymbolsTotal(true); ++i )
   {
      currentSymbol = SymbolName(i, true);
      Print(currentSymbol);
      checkDonchian(currentSymbol);
   
      Sleep(1000);
   }
   Sleep(1000);
   } 
   
//---
   return(INIT_SUCCEEDED);
  }

int checkDonchian(string currentSym)
{

   double SsMax=0,SsMin=0;
 
   double high[];
   double low[];
   
   int copiedDataCountHigh = CopyHigh(currentSym, InpPeriod, 0, DonchianPeriod, high);
   int copiedDataCountLow = CopyLow(currentSym, InpPeriod, 0, DonchianPeriod, low);
   
   return 0;
}
Alain Verleyen
Moderator
30707
Alain Verleyen 2013.08.07 12:53  
zubr:

This is the code in short resulting after approx. 6 min running to an out of memory:

 

Are you talking of 6 min on a live chart ?
zubr
172
zubr 2013.08.07 13:33  
angevoyageur:
Are you talking of 6 min on a live chart ?

I mean when I attach the EA to a chart it crashes after about 6 minutes (depends on current system usage). Can you reproduce it? 

12
To add comments, please log in or register