Download MetaTrader 5
To add comments, please log in or register
We have launched Spanish and Portuguese versions of the website. Try them!
Tom Clayson
215
Tom Clayson 2014.04.29 10:45 

I am getting messages of

"XXX bytes of leaked memory"

"YYY objects of type DbleLess left"

"ZZZ undeleted objects left"

The function is called from the main OnStart() loop. I thought I was deleting the objects - so why the memory leak?

void UpdateNearestLevels(int SupOrRes,const int Bar,double& SP_Levels[],double& SP_Times[],double& OppSP_Levels[],double& OppSP_Times[],
double& Next_Level[],const double &O[],const double &H[],const double &L[],const double &C[],const datetime &T[]) {

   if( Bar<2*ActualBarsEitherSide) {
      return;
   }

   Comparable* Operator1;
   Comparable* Operator2;
   if(SupOrRes==Res) {
      Operator1 = new DblGreater;
      Operator2 = new DblLess;
   }
   else {
      Operator1 = new DblLess;
      Operator2 = new DblGreater;
   }

/* Rest of code here */

   delete Operator1;
   Operator1=NULL;
   delete Operator1;
   Operator2=NULL;

}
Pasi Hakamaki
4001
Pasi Hakamaki 2014.04.29 11:20  
whitebloodcell:

I am getting messages of

"XXX bytes of leaked memory"

"YYY objects of type DbleLess left"

"ZZZ undeleted objects left"

The function is called from the main OnStart() loop. I thought I was deleting the objects - so why the memory leak?

void UpdateNearestLevels(int SupOrRes,const int Bar,double& SP_Levels[],double& SP_Times[],double& OppSP_Levels[],double& OppSP_Times[],
double& Next_Level[],const double &O[],const double &H[],const double &L[],const double &C[],const datetime &T[]) {

   if( Bar<2*ActualBarsEitherSide) {
      return;
   }

   Comparable* Operator1;
   Comparable* Operator2;
   if(SupOrRes==Res) {
      Operator1 = new DblGreater;
      Operator2 = new DblLess;
   }
   else {
      Operator1 = new DblLess;
      Operator2 = new DblGreater;
   }

/* Rest of code here */

   delete Operator1;
   Operator1=NULL;
   delete Operator1;
   Operator2=NULL;

}

You seem to be deleting Operator1 twice at the end of your code. That might be causing the leak.

Tom Clayson
215
Tom Clayson 2014.04.29 13:16  
Candles:

You seem to be deleting Operator1 twice at the end of your code. That might be causing the leak.

(Facepalm). Thanks for pointing that out! My problems always seem to be simple things like this...
Pasi Hakamaki
4001
Pasi Hakamaki 2014.04.29 13:46  
whitebloodcell:
(Facepalm). Thanks for pointing that out! My problems always seem to be simple things like this...
Me too, been there, done that and still fall victim to this at times :)
/
To add comments, please log in or register