Features of the mql5 language, subtleties and tricks - page 200

 
fxsaber:
Object*-functions are very laggy if you drag the graph with the mouse.
Can they just redraw?
 
Nikolai Semko:
Can they just be redrawn?

ObjectFind, for example, what does it have to do with redrawing?

 
fxsaber:

ObjectFind, for example, what does it have to do with redrawing?

Ah, that's not what I had in mind.
 

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql5, tips and tricks

fxsaber, 2020.03.04 08:58

I was only suspicious before, now it's confirmed. It's easy to get memory leaks when working with resources.

The script via SB outputs a graph of a numeric array to the chart. You can then manually delete this chart (object), but the resource assigned to this chart will remain forever hanging in memory in read-only mode. It cannot be deleted, because only the owner script can delete it (see the highlighted line).


There is no functionality in MQL to free up so occupied memory. Be especially careful with this on VPS.


How can I free the memory in Terminal after the scripts which do not clean up after themselves (or after abnormal stops)?

// После окончания работы скрипта Терминал потребляет дополнительные 4 Gb. Как освободить?
void OnStart()
{
  uint Data[];
  
  ArrayResize(Data, 1 e6);
  
  for (int i = 0; i < 1000; i++)  
    ResourceCreate("::" + (string)i, Data, ArraySize(Data), 1, 0, 0, ArraySize(Data), COLOR_FORMAT_ARGB_NORMALIZE);
}

In TaskManager (F2) memory consumption is shown very well. Now only restarting the Terminal helps.

 
fxsaber:

How to free up memory in Terminal after running scripts that do not clean up after themselves (or after an abnormal stop)?

In TaskManager (F2) memory consumption is perfectly visible. At the moment only Terminal restarting helps.

Normally, it is necessary to call ResourceFree for each resource.

On crashes there is nothing you can do. The only way to do that is to make a dll which will be used to create resources and clean them up after thread shutdown.

 
Vladimir Simakov:

Normally, you have to call ResourceFree for each resource.

There is nothing you can do in case of emergency shutdown. Only if you make your own dll, through which to create resources, which, when the thread is turned off, will clear them itself.

The emergency shutdown also includes debug interruption.

 
fxsaber:

The crash includes a debug interruption.

By standard mql means - memory leakage. Only your own implementation of all this should be written in a mature way. Given that DllMain with DLL_THREAD_DETACH isn't likely to be called when such a thread terminates, it's not the most trivial task, but it's manageable.

UPD: This thread should go in the bug thread. IMHO
 

Forum on trading, automated trading systems and trading strategy testing

New version of MetaTrader 5 build 2650: Background Loading of Charts and Improvements in the MQL5 Code Profiler

fxsaber, 2020.10.23 18:44

Now in the chart bar you cannot see which chart the Expert Advisor is running on and which one it is not.

Is it possible to add a distinguishing sign? For example, if EURUSD chart is working with an EA, then add an asterisk at the end: EURUSD*. In general, something that could be visually catchy.

A lot of charts, some are running EAs on some. Probably useful for indicators as well, but I don't use it. That's why I don't know.


For some reason there is no hotkey for the list of running EAs. You can only open it with the mouse.

F2 now. Press ENTER on an EA - we will switch to its chart and a tree with the path to it will open in the Navigator. Second time ENTER - source in ME.

 
Previously, an internal error in the EA did not cause it to close.
2021.03.18 11:41:47.413 zero divide in 'Test9.mq5' (550,5)
2021.03.18 11:42:26.619 array out of range in 'Test9.mq5' (550,8)

More recently, it is causing the problem.


Before, a Market client could get around the problem by rebooting the terminal. Now it doesn't.

 

Forum on trading, automated trading systems and strategy testing

New version of MetaTrader 4 build 1330

fxsaber, 2021.04.03 00:21

// Конструкция обнаружения бесконечных циклов.
class LOOP
{
private:
  static int PrevLine;    
  static uint PrevTime;
  
public:
#define  LOOP_CHECKTIME 100000 // Максимальная длительность (в миллисекундах) выполнения цикла

  static bool CheckFirst( const int Line )
  {
    if (Line != PrevLine)
    {
      LOOP::PrevTime = ::GetTickCount();
      LOOP::PrevLine = Line;
    }
      
    return(!::IsStopped() && ::GetTickCount() - LOOP::PrevTime < LOOP_CHECKTIME);
  }
  
  static bool Description( const string Str )
  {
    if (!::IsStopped() && (::GetTickCount() - LOOP::PrevTime > LOOP_CHECKTIME))
    {
      ::MessageBox("Endless loop:\n" + Str);
  
      LOOP::PrevTime = ::GetTickCount();
    }
    
    return(!::IsStopped());
  }
#undef  LOOP_CHECKTIME
};

static int LOOP::PrevLine = 0;
static uint LOOP::PrevTime = 0;


#define _CS(A) ((LOOP::CheckFirst(__LINE__) || LOOP::Description(__FILE__ + "\n" + (string)__LINE__ + "\n" + __FUNCSIG__ + "\nCondition: " + #A)) && (A))


Example usage.

void OnInit()
{
  for (uint i = 5; _CS(i >= 0); i--)
    ;
}
Reason: