!!! undeleted objects left - page 2

 
Reporting Memory Leaks in Strategy Tester
Reporting Memory Leaks in Strategy Tester
  • www.mql5.com
Monitoring of memory leaks in the strategy tester
 
Anil Varma #:

Thanks Paul

I think I have got a solution to find it, as load it from a single file, I can disable the load and will get error of not finding this class. I can check it from there.

You mentioning to share the code (if I need a solution) was not needed at all. I have tried this in past and most of the time it get unchecked.

'there are no tools beyond what is in the editor' is the right and good enough answer to my problem.

no problem, if want to be picky about the answers you get then I won't bother answering anymore of your questions 

 
Anil Varma #:

Thanks Paul

I think I have got a solution to find it, as load it from a single file, I can disable the load and will get error of not finding this class. I can check it from there.

You mentioning to share the code (if I need a solution) was not needed at all. I have tried this in past and most of the time it get unchecked.

'there are no tools beyond what is in the editor' is the right and good enough answer to my problem.

Not correct. There are tools, like this library

Reporting Memory Leaks in Strategy Tester
Reporting Memory Leaks in Strategy Tester
  • www.mql5.com
Monitoring of memory leaks in the strategy tester
 
Amir Yacoby #:

Not correct. There are tools, like this library

You have already posted that so what’s your point
 
Amir Yacoby #:
Use this library 

Thanks a lot Amir :)

I have tried using lib and it helped me to pin point where the problem is causing. However below is the code and I have deleted the object but still getting this warning.

Any further clues what could be wrong?

//+-----------------------------------------------------------------------------------------------------------------------------+
//| CLASS:              CExpertBase
//| APPLICATION:  EXPERT BASE FOR USING MULTI CURRENCY ALGO TRADING
//| NOTE:                                       DIFFERENT INSTANCES OF CExpertBase FOR EACH SYMBOL / ASSET
//+-----------------------------------------------------------------------------------------------------------------------------+
class CExpertBase final {

public:

        CExpertBase(string pSymbol,const string &pTradedSymbols[],double pRiskPortfolio,double pRiskPerTrade,int pATRPeriod);
         ~CExpertBase();
        
                int                                                                                     OnInit();
                void                                                                                    OnTick();
                void                                                                                    OnTimer();
        //+---------------------------------------------------------------------------------------------------------------------------+
        //| LOAD FUNCTION CLASS(s)
        //+---------------------------------------------------------------------------------------------------------------------------+
                private:
                        CMarketInfo                                                     *cMarketInfo;                                                                                   // Does not require any initialization parameters

}; // END Of Class DEFINITION
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                     CExpertBase()
//| APPLICATION:        INITILIZATION OF CLASS
//+-----------------------------------------------------------------------------------------------------------------------------+
CExpertBase::CExpertBase(string pSymbol,const string &pTradedSymbols[],double pRiskPortfolio,double pRiskPerTrade,int pATRPeriod) {

                cMarketInfo = new CMarketInfo();

}; // END Of constructor method CExpertBase()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                     ~CExpertBase()
//| APPLICATION:        DEFUALT DECONSTRUCTOR METHOD
//+-----------------------------------------------------------------------------------------------------------------------------+
CExpertBase::~CExpertBase() {

                EventKillTimer();

                // Delete Function Class(s)
                delete cMarketInfo;

}; // END Of deconstructor method CExpertBase()
 
Are you calling destructor for CExpertBase()?

Try to stop the debugger in constructor and destructor making sure they run the same number of times.
 

Either CExpertBase is not being deleted, or you have other instances of CMarketInfo.

It’s easy to check if you have other instances of CMarketInfo using a search (as I showed in my previous post). I think it will take up to 20 minutes for 5000 lines of code. Perhaps even less if you know how to search across multiple files at once (personally, I don’t use search across multiple files, so I don’t know exactly how it works).
 
Amir Yacoby #:
Are you calling destructor for CExpertBase()?

Try to stop the debugger in constructor and destructor making sure they run the same number of times.
//+-----------------------------------------------------------------------------------------------------------------------------+
//| EXPERT:       OnInit() Initialization Function
//+-----------------------------------------------------------------------------------------------------------------------------+
int OnInit() {

        //+---------------------------------------------------------------------------------------------------------------------------+
        //| SET UP EXPERT BASE CLASS(s) FOR EACH TRADABLE SYMBOL FROM sSymbolArray
        //+---------------------------------------------------------------------------------------------------------------------------+
                // CONVERT string TradeSymbols variable to the symbol string 'AND' populate TradedSymbols[]
                mSymbolsCount = StringSplit(InpTradeSymbols, '|', TradedSymbols);
                PrintFormat("MultiSymbol EA will process [%i] Symbols",mSymbolsCount);

                ArrayResize(cExperts,mSymbolsCount);
                for(int i = 0; i < mSymbolsCount; i++) {
                        // Set the each symbol expert class, as well pass in TradeSymbols[] for calculating Correlation Coefficient at BaseStragey Class Level
                        cExperts[i] = new CExpertBase(TradedSymbols[i],TradedSymbols,RiskPortfolio,RiskPosition,ATR_MAPeriod);
                        // Set the indicator(s) parameter values for the symbol
                        SetIndicatorParameters(i);
                        // Initialize symbol Expert class
                        cExperts[i].OnInit();                                                                                                           // OnInit() FAILED or SUCCEEDED check to be implemented for each Symbol
                }
                return(INIT_SUCCEEDED);

} // END of function OnInit()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| EXPERT:       OnDeinit() DeInitialization Function
//+-----------------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason) {

                for(int i = 0; i < mSymbolsCount; i++) {
                        delete cExperts[i];
                }
} // END of function OnDeinit()

Yes I did call the destructor of CExpertBase in Expert, but it is a loop for multi symbols.

Also I am having this problem in live test and not in strategy tester. Sorry I forgot to mention earlier.

 
Amir Yacoby #:
Try to stop the debugger in constructor and destructor making sure they run the same number of times.

I marked debugger and start of constructor and destructor.

It did not stop at destructor. in first two attempts.

However now when I run debugger, it hangs off with Waiting For Update error

 
Anil Varma #:

I marked debugger and start of constructor and destructor.

It did not stop at destructor. in first two attempts.

However now when I run debugger, it hangs off with Waiting For Update error

Any ArrayResize for cExperts somewhere? A change in mSymbolsCount?

Try to add the static instance counter m_occ to CMarketInfo

*update Also you can view the id of the objects not deleted with m_id printed in constructor/destructor

class CMarketInfo
  {
private:
   int               m_id;	
public:
   static int        m_occ;
                     CMarketInfo()
     {
      m_occ++;
      m_id=m_occ;
      Print("Instantiating ",m_id);
     }
                    ~CMarketInfo()
     {
      m_occ--;
      Print("Deleting ",m_id);
     }
  };
int CMarketInfo::m_occ=0;

And print it after delete

//+-----------------------------------------------------------------------------------------------------------------------------+
//| EXPERT:       OnDeinit() DeInitialization Function
//+-----------------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason) {

                for(int i = 0; i < mSymbolsCount; i++) {
                        delete cExperts[i];
                Print("Total left objects : ",CMarketInfo::m_occ);
                }
} // END of function OnDeinit()