"XXX bytes of leaked memory" "YYY objects of type DbleLess left" "ZZZ undeleted objects left"

 

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;

}
 
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.

 
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...
 
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 :)
Reason: