0

I'm new to programming and have gotten stuck on how I can delete my pointer arrays before termination.

Cuz MT4 crashes when I try to add the EA with the reason timeout.

this is the code and arrays I need to terminate:

  string parts[];
  StringSplit(row, ' ', parts);
  int len = ArraySize(parts);
  string debug = "";

  for(int k = 0; k < len; k++)
     debug += "|" + parts[k]; 

  if(len != 7)
     continue;

  Signal *s      = new Signal();
  s.signal_time  = time;
  s.order_type   = parts[4] == "BUY" ? OP_BUYLIMIT : OP_SELLLIMIT;
  s.symbol       = parts[0];      
  m_signals.Add(s);

I'm very thankful for all help with this :D

Gotten this far:

void SignalList::Signal
{ 
    //--- service pointer for working in the loop 
    CObject* Signal; 
    //--- go through loop and try to delete dynamic pointers 
    while(CheckPointer(m_signals) != POINTER_INVALID) 
    { 
      Signal *s      = new Signal(); 
      m_signals=m_signals.Next(); 
      if(CheckPointer(Signal)==POINTER_DYNAMIC) 
        { 
         Print("Dynamic object ", Signal.Identifier(), " to be deleted"); 
         delete (Signal); 
        } 
      else Print("Non-dynamic object ", Signal.Identifier(), " cannot be deleted"); 
     } 
//--- 
}

This is the source code which my code is based upon: https://stackoverflow.com/a/52104040/12452532

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ville07
  • 1
  • 2
  • What kind of crash happens? Do not forget to declare `class Signal : public CObject`, in order to delete them all - `if(CheckPointer(m_signals)==POINTER_DYNAMIC)delete(m_signals);` and of course `m_signals` must be `CArrayObj*` – Daniel Kniaz Nov 29 '19 at 16:54
  • @DanielKniaz I have updated the post with the information you asked for I didn't have any type of terminate function so the crash was expected I have tried implementing what you said. but m_signs are declared as equal to SignalList which is a class in itself which references the Cobject: look at source code for more information. Thank you so much for your help! – ville07 Nov 29 '19 at 20:48
  • If the reason is timeout, check your `OnInit()` first, most likely ea cannot finish initialization (e.g., it waits and looks for a file that does not exist). The link you added use (where possible) global objects (declared once, initialized at start and deleted in the end) that do not require you to delete such objects. – Daniel Kniaz Nov 30 '19 at 08:58

0 Answers0