Order Of Events When Recompile - Strange


I have the following situation:

My EA creates a handler of any indicator, in the OnInit() function.

In the OnDeInit() function of my EA I call the functions: a clear for the memory data and another removal for the indicator:

void OnDeinit(const int reason) {
 ChartIndicatorDelete(0, 0, "myIndicator");

Okay, at this point when I remove the EA from the chart it successfully removes the indicator.

The problem is when I recompile my system.
. As far as I know, the recompile follows the following process:

EA:OnDeInit() > Indicator:OnDeInit() > EA:OnInit() > Indicator:OnInit()

But the process works differently:

EA:OnDeInit() > EA:OnInit() > Indicator:OnInit() > Indicator:OnDeInit()

I don't understand why that... In my understanding, the order of events diverges from what I understand to be correct.

The recompilation order is different, first it calls deinitialization, then initialization
I found the solution, but I believe there are better alternatives for this..

I put a sleep(5000).

Why? It is likely that within this time the indicator has been removed, so when you delete an indicator from the chart, you need to wait.

I just didn't think it was cool that I had to use sleep for it, I thought that ChartRedraw() would fulfill the function of processing an event queue that it would remove, but to no avail.