Amir Yacoby #: Any ArrayResize for cExperts somewhere? A change in mSymbolsCount?
Good morning Amir
ArrayResize ... done at Expert OnInit() and no changes in mSymbolCount. Currently there is only one symbol in EA, and possibly that is the one not being deleted. Other 4 instances seems to come from instantiation from Class(s) other than EA.
2024.06.13 09:41:20.249AlgoEA (XAUUSD,M15)void OnDeinit(const int): Total Objects Left : 1
2024.06.13 09:41:20.249AlgoEA (XAUUSD,M15)1 undeleted objects left
2024.06.13 09:41:20.249AlgoEA (XAUUSD,M15)1 object of type CMarketInfo left
2024.06.13 09:41:20.249AlgoEA (XAUUSD,M15)64 bytes of leaked memory
Below is the relevant codes.
//+-----------------------------------------------------------------------------------------------------------------------------+//| OBJECT: Instantiation//+-----------------------------------------------------------------------------------------------------------------------------+// Create pointer array to hold BaseExpertClass for each symbolCExpertBase*cExperts[];
//+-----------------------------------------------------------------------------------------------------------------------------+//| EXPERT: OnInit() Initialization Function//+-----------------------------------------------------------------------------------------------------------------------------+intOnInit() {
//+---------------------------------------------------------------------------------------------------------------------------+//| SET UP EXPERT 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 LevelcExperts[i] = new CExpertBase(TradedSymbols[i],TradedSymbols,RiskPortfolio,RiskPosition,ATR_MAPeriod);
// Set the indicator(s) parameter values for the symbol
SetIndicatorParameters(i);
// Initialize symbol Expert classcExperts[i].OnInit(); // OnInit() FAILED or SUCCEEDED check to be implemented for each Symbol
}
//+---------------------------------------------------------------------------------------------------------------------------+return(INIT_SUCCEEDED);
} // END of function OnInit()//+-----------------------------------------------------------------------------------------------------------------------------+//| EXPERT: OnDeinit() DeInitialization Function//+-----------------------------------------------------------------------------------------------------------------------------+voidOnDeinit(constint reason) {
//+---------------------------------------------------------------------------------------------------------------------------+//| ON EXIT, DELETE ALL ExpertBase CLASS(s) CREATED BY EXPERT//+---------------------------------------------------------------------------------------------------------------------------+for(int i = 0; i < mSymbolsCount; i++) {
deletecExperts[i];
PrintFormat("%s: Total Objects Left : %2d",__FUNCSIG__,CMarketInfo::mOCC);
}
} // END of function OnDeinit()
class CMarketInfo {
private:
int mID;
public:
staticint mOCC;
CMarketInfo() { mOCC++;
mID = mOCC;
PrintFormat("%s: Instantiating: %2d",__FUNCSIG__,mID);
}
~CMarketInfo() { mOCC--;
mID = mOCC;
PrintFormat("%s: Deleting: %2d",__FUNCSIG__,mID);
}
public:
bool IsMarketOpen(string pSymbol,datetime pTime);
}; // END of class definitionint CMarketInfo::mOCC = 0; // Initialize the variable
EDIT: CExpertBase class code also included now as below
class CExpertBase final {
public:
CExpertBase(string pSymbol,conststring &pTradedSymbols[],double pRiskPortfolio,double pRiskPerTrade,int pATRPeriod);
~CExpertBase();
intOnInit();
voidOnTick();
voidOnTimer();
private:
CMarketInfo *cMarketInfo; // Does not require any initialization parameters
}; // END Of Class DEFINITION//+-----------------------------------------------------------------------------------------------------------------------------+//| METHOD: CExpertBase()//| APPLICATION: INITILIZATION OF CLASS//+-----------------------------------------------------------------------------------------------------------------------------+
CExpertBase::CExpertBase(string pSymbol,conststring &pTradedSymbols[],double pRiskPortfolio,double pRiskPerTrade,int pATRPeriod) {
cMarketInfo = new CMarketInfo();
}; // END Of constructor method CExpertBase()//+-----------------------------------------------------------------------------------------------------------------------------+//| METHOD: ~CExpertBase()//| APPLICATION: DEFUALT DECONSTRUCTOR METHOD//+-----------------------------------------------------------------------------------------------------------------------------+
CExpertBase::~CExpertBase() {
// Delete Function Class(s)// 2024.06.11 10:02:48.654 AlgoEA (XAUUSD,M15) - File ExpertBase.mqh Line 121deletecMarketInfo;
}; // END Of deconstructor method CExpertBase()//+-----------------------------------------------------------------------------------------------------------------------------+//| EXPERT: OnInit() Initialization Function//+-----------------------------------------------------------------------------------------------------------------------------+int CExpertBase::OnInit() {
//+---------------------------------------------------------------------------------------------------------------------------+//| SET UP TRADING DAYS AND TRADING HOURS FOR mSymbol, //+---------------------------------------------------------------------------------------------------------------------------+cMarketInfo = new CMarketInfo(); // Input parameters ... NONE
cMarketInfo.SetSymbolTradeTimes(vSymbolParam.symbol,vSymbolTradeHours); // Initialize Trading Hours for the CExpertBase Class's Symbol
mCloseDoW = 5;
mCloseHour = ((int)(((vSymbolTradeHours[mCloseDoW].timeClose)%86400)/3600)); // return Closing Hour 23:55 as 23
mCloseMinute = (int(((vSymbolTradeHours[mCloseDoW].timeClose)%3600)/60)) - 5; // Subtracted 5 minutes
SetNextCloseTime();
//PrintFormat("%s CloseALL Trade on WeekDay[5] at Hours[%s:%s]",vMethod,IntegerToString(mCloseHour,2,'0'),IntegerToString(mCloseMinute,2,'0'));return(INIT_SUCCEEDED);
} // END of function OnInit()
ArrayResize ... done at Expert OnInit() and no changes in mSymbolCount. Currently there is only one symbol in EA, and possibly that is the one not being deleted. Other 4 instances seems to come from instantiation from Class(s) other than EA.
I have tried your suggestions and indeed there is problem with number of instantiations and deletions.
Paul Anscombe #: So you finally tried what I said to do in post #1 four days ago and now you can see your problem and the fix is simple.
Hi Paul
I personally feel that Amir is trying to find error more logically then just simple guess work.
Now we have pin-pointed where the error is caused, but there seems to issue something else (a technical glitch or coding error) not just a matter of deleting the object, which is what you are suggesting.
May be you are reaching to conclusion too fast without realizing the real problem.
If you think deleting the object is the only solution, then look at the Expert code above, there is a command to delete, however object is still left. I will be glad if you can answer why it is still left.
I personally feel that Amir is trying to find error more logically then just simple guess work.
Now we have pin-pointed where the error is caused, but there seems to issue something else (a technical glitch or coding error) not just a matter of deleting the object, which is what you are suggesting.
May be you are reaching to conclusion too fast without realizing the real problem.
If you think deleting the object is the only solution, then look at the Expert code above, there is a command to delete, however object is still left. I will be glad if you can answer why it is still left.
You are making massive assumptions about what I think…. When did I suggest simple guess work?
You made it clear you didn’t like my suggestions, which you have now done and which would have led to this point 4 days ago so pointless me telling you how to fix it now because you won’t be interested. I merely posted again in the hope you realise your mistake, like so many here, of being so dismissive of answers received, but no your latest post is still dismissive
If a person already knows the answer they want why ask a question?
Yes I agree, there was a mistake to declaring it twice, and this fact was hidden behind so many other lines of code in between. Here when I posted it, I removed unrelated code, however still failed to recognize it :)
THANKS A LOT for pin-pointing the exact cause and resolving it too.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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
And print it after delete
Thanks a lot Amir
Will try them out.
Any ArrayResize for cExperts somewhere? A change in mSymbolsCount?
Good morning Amir
ArrayResize ... done at Expert OnInit() and no changes in mSymbolCount. Currently there is only one symbol in EA, and possibly that is the one not being deleted. Other 4 instances seems to come from instantiation from Class(s) other than EA.
I have tried your suggestions and indeed there is problem with number of instantiations and deletions.
2024.06.13 09:40:54.876 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 1
2024.06.13 09:40:54.876 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 2
2024.06.13 09:40:54.876 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 3
2024.06.13 09:40:54.883 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 4
2024.06.13 09:40:55.013 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 5
2024.06.13 09:41:20.248 AlgoEA (XAUUSD,M15) CMarketInfo::~CMarketInfo(): Deleting: 4
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) CMarketInfo::~CMarketInfo(): Deleting: 3
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) CMarketInfo::~CMarketInfo(): Deleting: 2
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) CMarketInfo::~CMarketInfo(): Deleting: 1
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) void OnDeinit(const int): Total Objects Left : 1
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) 1 undeleted objects left
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) 1 object of type CMarketInfo left
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) 64 bytes of leaked memory
Below is the relevant codes.
EDIT: CExpertBase class code also included now as below
Good morning Amir
ArrayResize ... done at Expert OnInit() and no changes in mSymbolCount. Currently there is only one symbol in EA, and possibly that is the one not being deleted. Other 4 instances seems to come from instantiation from Class(s) other than EA.
I have tried your suggestions and indeed there is problem with number of instantiations and deletions.
2024.06.13 09:40:54.876 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 1
2024.06.13 09:40:54.876 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 2
2024.06.13 09:40:54.876 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 3
2024.06.13 09:40:54.883 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 4
2024.06.13 09:40:55.013 AlgoEA (XAUUSD,M15) CMarketInfo::CMarketInfo(): Instantiating: 5
2024.06.13 09:41:20.248 AlgoEA (XAUUSD,M15) CMarketInfo::~CMarketInfo(): Deleting: 4
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) CMarketInfo::~CMarketInfo(): Deleting: 3
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) CMarketInfo::~CMarketInfo(): Deleting: 2
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) CMarketInfo::~CMarketInfo(): Deleting: 1
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) void OnDeinit(const int): Total Objects Left : 1
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) 1 undeleted objects left
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) 1 object of type CMarketInfo left
2024.06.13 09:41:20.249 AlgoEA (XAUUSD,M15) 64 bytes of leaked memory
Below is the relevant codes.
So you finally tried what I said to do in post #1 four days ago and now you can see your problem and the fix is simple.
Hi Paul
I personally feel that Amir is trying to find error more logically then just simple guess work.
Now we have pin-pointed where the error is caused, but there seems to issue something else (a technical glitch or coding error) not just a matter of deleting the object, which is what you are suggesting.
May be you are reaching to conclusion too fast without realizing the real problem.
If you think deleting the object is the only solution, then look at the Expert code above, there is a command to delete, however object is still left. I will be glad if you can answer why it is still left.
Why CExpertBase instansiates CMarketInfo twice (once in it's constructor and once in OnInit()) ?
Hi Paul
I personally feel that Amir is trying to find error more logically then just simple guess work.
Now we have pin-pointed where the error is caused, but there seems to issue something else (a technical glitch or coding error) not just a matter of deleting the object, which is what you are suggesting.
May be you are reaching to conclusion too fast without realizing the real problem.
If you think deleting the object is the only solution, then look at the Expert code above, there is a command to delete, however object is still left. I will be glad if you can answer why it is still left.
Why CExpertBase instansiates CMarketInfo twice (once in it's constructor and once in OnInit()) ?
Also if still not helping, remove the second line in the attached pic for more correct delete printing
~CMarketInfo() { mOCC--; // mID = mOCC; <=== Remove this line PrintFormat("%s: Deleting: %2d",__FUNCSIG__,mID);CMarketInfo twice
Hi Amir
Yes I agree, there was a mistake to declaring it twice, and this fact was hidden behind so many other lines of code in between. Here when I posted it, I removed unrelated code, however still failed to recognize it :)
THANKS A LOT for pin-pointing the exact cause and resolving it too.
Allocating an object twice and saving them in the same pointer makes the first object lost in memory and undeletable.
this is technical information I was not aware of earlier. But logically also it is not correct to declare something twice.