help on Errors: leaked string/memory and objects left | Even though I have deleted the Class(s) in OnDeinit()

 
int OnInit() {

                cMASlow = new CiVWMA(gSymbol,gTimeFrame,MAPeriodSlow,VWMA_AppliedPrice,VWMA_MAMethod);
                cMAMid  = new CiVWMA(gSymbol,gTimeFrame,MAPeriodMid,VWMA_AppliedPrice,VWMA_MAMethod);
                cMAFast = new CiVWMA(gSymbol,gTimeFrame,MAPeriodFast,VWMA_AppliedPrice,VWMA_MAMethod);
                cBand   = new CiBand(gSymbol,gTimeFrame,iBandParam);
                cTrend  = new CGetTrend(gSymbol,gTimeFrame,iVWMAParam,iBandParam,MAPeriodSlow,MAPeriodMid,MAPeriodFast);

                return(INIT_SUCCEEDED);

} // End of function OnInit()
void OnDeinit(const int reason) {

                delete cMASlow;
                delete cMAMid;
                delete cMAFast;
                delete cMASpread;
                delete cMARange;
                delete cBand;
                delete cTrend;

} // End of indicator function OnDeinit()

I have started getting following error, after #include following class in the indicator iCPatterns_v2.02:

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 1 leaked strings left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 5 undeleted objects left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 1 object of type CGetTrend left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 3 objects of type CiVWMA left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 1 object of type CiBand left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 1280 bytes of leaked memory

//+-----------------------------------------------------------------------------------------------------------------------------+
//| CLASS:                              CGetTrend.mqh
//| APPLICATION:        To find price trend direction
//+-----------------------------------------------------------------------------------------------------------------------------+
class CGetTrend final : public CIndicatorBase {

public:
                CGetTrend() : CIndicatorBase(_Symbol,_Period) { }
                CGetTrend(string pSymbol,ENUM_TIMEFRAMES pTimeFrame,SParam_iVWMA &Param_iVWMA,SParam_iBand &Param_iBand,
                                                        int PeriodTrendSlow=200,int PeriodTrendMid=55,int PeriodTrendFast=21);
         ~CGetTrend();

private:

                CiVWMA                                          *cMASlow;        // VWMA Long Term Trend
                CiVWMA                                          *cMAMid;         // VWMA Medium/Mid Term Trend
                CiVWMA                                          *cMAFast;        // VWMA Short Term Trend

                CiBand                                          *cBand;          // Tripple Bollinger Bands

public:

                CENUM_TREND                                     trend(int pIdx);

}; // END Of Class Definition
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                             CGetTrend()
//| APPLICATION:        Class 'Parametric' Constructor
//+-----------------------------------------------------------------------------------------------------------------------------+
CGetTrend::CGetTrend(string pSymbol,ENUM_TIMEFRAMES pTimeFrame,SParam_iVWMA &Param_iVWMA,SParam_iBand &Param_iBand,
                                                                                 int PeriodTrendSlow=200,int PeriodTrendMid=55,int PeriodTrendFast=21)
        : CIndicatorBase(pSymbol,pTimeFrame) {                                   // Call ParentClass constructor

                mSymbol                 = pSymbol;
                mTimeFrame              = pTimeFrame;

                // Note: Volume Type is defaulted 'mAppliedVolume' from CIndicatorBase Class
                cMASlow = new CiVWMA(mSymbol,pTimeFrame,PeriodTrendSlow,Param_iVWMA.appliedPrice,Param_iVWMA.maMethod);
                cMAMid  = new CiVWMA(mSymbol,pTimeFrame,PeriodTrendMid,Param_iVWMA.appliedPrice,Param_iVWMA.maMethod);
                cMAFast = new CiVWMA(mSymbol,pTimeFrame,PeriodTrendFast,Param_iVWMA.appliedPrice,Param_iVWMA.maMethod);
                cBand   = new CiBand(mSymbol,mTimeFrame,Param_iBand);

} // END Of method CGetTrend()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                             ~CGetTrend()
//| APPLICATION:        Class 'Destructor'
//+-----------------------------------------------------------------------------------------------------------------------------+
CGetTrend::~CGetTrend() {

                delete cMASlow;
                delete cMAMid;
                delete cMAFast;
                delete cBand;

} // END Of method ~CGetTrend()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| FUNCTION:           trend()
//+-----------------------------------------------------------------------------------------------------------------------------+
CENUM_TREND CGetTrend::trend(int pIdx) {

                double VWMASlow = cMASlow.GetIndexMA(pIdx);
                double VWMAMid  = cMAMid.GetIndexMA(pIdx);
                double VWMAFast = cMAFast.GetIndexMA(pIdx);

                CENUM_TREND slopeSlow = cMASlow.slope(pIdx);
                CENUM_TREND slopeMid  = cMAMid.slope(pIdx);
                CENUM_TREND slopeFast = cMAFast.slope(pIdx);

                SiBand  Band[1];
                cBand.GetIndexBands(pIdx,Band);

                CENUM_TREND vTrend = WRONG_VALUE;
        //+---------------------------------------------------------------------------------------------------------------------------+
        //| TREND LONG
        //+---------------------------------------------------------------------------------------------------------------------------+
                if(VWMASlow < Band[0].lowerBase && (VWMASlow < VWMAMid && VWMAMid < VWMAFast)) {                                // VWMA in Ascending hierarchy
                        if(slopeSlow == TREND_LONG && slopeMid == TREND_LONG  && slopeFast == TREND_LONG)                       return(TREND_LONG);
                        if(slopeSlow == TREND_LONG && slopeMid == TREND_LONG  && slopeFast == TREND_SHORT)                      return(TREND_LONG_RETRACE);
                        if(slopeSlow == TREND_LONG && slopeMid == TREND_SHORT && slopeFast == TREND_SHORT)                      return(TREND_LONG_RETRACE);
                }
        //+---------------------------------------------------------------------------------------------------------------------------+
                return(vTrend);

} // END of method getTrendVWMA()
//+-----------------------------------------------------------------------------------------------------------------------------+
 
Anil Varma:

I have started getting following error, after #include following class in the indicator iCPatterns_v2.02:

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 1 leaked strings left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 5 undeleted objects left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 1 object of type CGetTrend left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 3 objects of type CiVWMA left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 1 object of type CiBand left

2024.04.04 11:53:43.630 iCPatterns_v2.02 (XAUUSD,M30) 1280 bytes of leaked memory

Try to debug your issue with this:

 
Dominik Egert #:
Try to debug your issue with this:

Hi Dominik

included the checker_for_memory_leaks.mqh into my Indicator.

Now I dont get error. However even if I comment out this include file, still now dont get error. Is it could be the memory catch?

THANKS a lot man :) 

 
Anil Varma #:

Hi Dominik

included the checker_for_memory_leaks.mqh into my Indicator.

Now I dont get error. However even if I comment out this include file, still now dont get error. Is it could be the memory catch?

THANKS a lot man :) 

There is not enough information given to pinpoint the issue.

My guess is, for some reason, you sometimes create objects which are not being deleted. That's the only obvious observation at the moment.

Maybe you leave the memory leak check in, and see if it happens again...


 
Dominik Egert #:
There is not enough information given to pinpoint the issue.

My guess is, for some reason, you sometimes create objects which are not being deleted. That's the only obvious observation at the moment.

Maybe you leave the memory leak check in, and see if it happens again...


Thanks for reply Dominik

I will leave memory leak check as suggested by you.