Download MetaTrader 5
To add comments, please log in or register
Start making profit using the Market. Publish your product!
Metal10k
31
Metal10k 2010.07.06 16:32 

Ok, I have been playing around with a class I had written for weeks now, trying to get to the bottom of a strange problem. For debugging purposes it seems logical to do the debugging of the workings of a class in a script, and whence the class is functional, import it into your expert. When doing this I noticed some descrepencies between the results (which have for all but one been solved), but the most notable was the fact that metatester.exe seemed to be increasing in ram usage linearly with time. It is important to state here that the script equivalent ran flawlessly and showed no such problems.

After retesting my own code numerous times I finally came to the conclusion it must have been something to do with the API calls to the indicator or the array buffers (my program uses an iterative creation and destruction of indicators for analysis). To test this I have created a simpler class which basically outlines where I thought the fault might have originated from. Interestingly enough, the same problem seems to arise, except 100x worse (I'm assuming partly because the intermediary calculations have been taken out). Running this code in an expert crashes my computer in a very short amount of time, however in a script seems to do exactly what it is supposed to. Please note this class is in no way of any use, its simply to test if the calls are working as intended.

If however I have made some totally illegal use of the array manipulation calls or indicator calls, my apologies. This particular problem however appears to me more reminiscent of a bug in the metatester.exe process. 

I have attached the code below, and for the sake of completion my tester log file. Please use with caution as this has crashed my machine.

 

//+------------------------------------------------------------------+
//|                                                     indclass.mqh |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+

struct indtest
{
   double IndicatorBuffer[], testbuffer[];
   int IndicatorHandle;
   int i, Start, Limit;
   int window;
   indtest();
   void PopulateBuffer();
   void processbuffer();
   ~indtest(){}
};

indtest::indtest()
{
IndicatorHandle = 0;
Start = 3;
Limit = 15;
i = Start;
window = 1000;
}

indtest::PopulateBuffer(void)
{
   IndicatorRelease(IndicatorHandle);

   if(i<Limit)
      {
      IndicatorHandle = iMA(_Symbol, _Period, i,0,MODE_EMA, PRICE_CLOSE);
      ArrayFree(IndicatorBuffer);               //prob not necessary, commenting out does not affect results
      ArrayResize(IndicatorBuffer,window+1);
      
      while(CopyBuffer(IndicatorHandle,0,0,window+1,IndicatorBuffer)<window) 
         Sleep(20);
       
      Print("handle = ", IndicatorHandle, " and buffer from 0 - ", IndicatorBuffer[0], ","
      ,IndicatorBuffer[1],",",IndicatorBuffer[2],",",IndicatorBuffer[3]); 
      processbuffer();
      i++;
      }
   else
      i = Start;

}

indtest::processbuffer(void)
{
   ArrayResize(testbuffer,window+1);
   for(int j = 0; j < window; j++)
      {
      
      testbuffer[j] = IndicatorBuffer[j];
      }
      
}



void RUNTEST()			//one liner to put in host program for testing
{
indtest testobject;

   for(int i = 0; i < 10000; i++)
      {
      testobject.PopulateBuffer();
      //Print("i = ", i);
      Sleep(2);
      }

}
Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.
Slawa
Moderator
6738
Slawa 2010.07.07 15:42  

Thank you for report. Memory leak fixed.

Metal10k
31
Metal10k 2010.07.07 16:57  
stringo:

Thank you for report. Memory leak fixed.

Thanks very much for looking into this, looking forward to the next update.
DarkRyder
509
DarkRyder 2016.06.13 23:54  
Is there a memory leak in the newest version? I have some of the .exe processes getting up into the 4gb+ range or higher. I also had one pc almost freeze entirely because metatester took all available ram.
Alain Verleyen
Moderator
29533
Alain Verleyen 2016.06.14 00:14  
DarkRyder:
Is there a memory leak in the newest version? I have some of the .exe processes getting up into the 4gb+ range or higher. I also had one pc almost freeze entirely because metatester took all available ram.
Why are you posting in an old thread ? Please use the good topic (or this one).
/
To add comments, please log in or register