Memory Exception

 

Hello. 
I'm having a problem with my EA. I have the following message repeating:

2022.07.06 13:11:46.206 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.206 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.207 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.207 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.207 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.207 MemoryException 1228800 bytes not available, 0 heapmin result

I am using a lot of indicators on this EA but I never had problem with it. 

I'm retrieving data like this (with shift = 0 or 1) :

if(signal == rsi_cl)

   {

      double array[];

      ArraySetAsSeries(array, true);

      CopyBuffer(indicator, 0, 0, shift+2, array);

      double value = NormalizeDouble(array[shift], 2);

      if (value < 30) return buy_signal;

      else if (value > 70) return sell_signal;

   }


Any idea where that can come from?

Thanks.

Arthur




 
The error seems to imply an "out of memory" condition.

Your code does not give enough details to say why this could happen.
 
Arthur Hatchiguian:

Hello. 
I'm having a problem with my EA. I have the following message repeating:

2022.07.06 13:11:46.206 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.206 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.207 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.207 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.207 MemoryException 1228800 bytes not available, 0 heapmin result

2022.07.06 13:11:46.207 MemoryException 1228800 bytes not available, 0 heapmin result

I am using a lot of indicators on this EA but I never had problem with it. 

I'm retrieving data like this (with shift = 0 or 1) :

if(signal == rsi_cl)

   {

      double array[];

      ArraySetAsSeries(array, true);

      CopyBuffer(indicator, 0, 0, shift+2, array);

      double value = NormalizeDouble(array[shift], 2);

      if (value < 30) return buy_signal;

      else if (value > 70) return sell_signal;

   }


Any idea where that can come from?

Thanks.

Arthur




You can monitor memory with these  handy functions - might help to print these out regularly to see if its a memory leak which builds gradually rather than a specific statement

      string strMemUsed       = IntegerToString(TerminalInfoInteger(TERMINAL_MEMORY_USED));
      string strMemAvail      = IntegerToString(TerminalInfoInteger(TERMINAL_MEMORY_AVAILABLE));
      string strMemTotal      = IntegerToString(TerminalInfoInteger(TERMINAL_MEMORY_TOTAL));
      string strMemPhys       = IntegerToString(TerminalInfoInteger(TERMINAL_MEMORY_PHYSICAL));
 
Dominik Christian Egert #:
The error seems to imply an "out of memory" condition.

Your code does not give enough details to say why this could happen.

Any ways or tools to control where the memory problem come from? Thanks

 
R4tna C #:

You can monitor memory with these  handy functions - might help to print these out regularly to see if its a memory leak which builds gradually rather than a specific statement

Thanks, i'll try it

 
R4tna C #:

You can monitor memory with these  handy functions - might help to print these out regularly to see if its a memory leak which builds gradually rather than a specific statement

-2

MemUsed: 1885

MemAvail: 14496

MemTotal: 16382

MemPhys: 8191


after init ind

MemUsed: 1916

MemAvail: 14466

MemTotal: 16382

MemPhys: 8191


-1

MemUsed: 1916

MemAvail: 14466

MemTotal: 16382

MemPhys: 8191


0

MemUsed: 1916

MemAvail: 14458

MemTotal: 16382

MemPhys: 8191


1

MemUsed: 1924

MemAvail: 14456

MemTotal: 16382

MemPhys: 8191


2

MemUsed: 1933

MemAvail: 14449

MemTotal: 16382

MemPhys: 8191


3

MemUsed: 1917

MemAvail: 14462

MemTotal: 16382

MemPhys: 8191


4

MemUsed: 1926

MemAvail: 14456

MemTotal: 16382

MemPhys: 8191


5

MemUsed: 1926

MemAvail: 14453

MemTotal: 16382

MemPhys: 8191


6

MemUsed: 1929

MemAvail: 14453

MemTotal: 16382

MemPhys: 8191

CTrade::PositionOpen: MQL5 program is stopped. Trading is disabled

CTrade::PositionOpen: MQL5 program is stopped. Trading is disabled

CTrade::PositionOpen: MQL5 program is stopped. Trading is disabled


7

MemUsed: 1998

MemAvail: 14384

MemTotal: 16382

MemPhys: 8191


8

MemUsed: 1998

MemAvail: 14384

MemTotal: 16382

MemPhys: 8191

I put prints all the way during init and ontick, everything looks good even the error happens right after the init.

I'm still digging to find the problem


 

Looks like you have enough RAM.. Doing a search in MQL5.com for  heapmin reveals two other forum posts where it is mentioned but its not clear to me what the solution could be.

If you have another PC try it on there, so you can identify whether it is a hardware/OS issue limited to your current host.

 
R4tna C #:

Looks like you have enough RAM.. Doing a search in MQL5.com for  heapmin reveals two other forum posts where it is mentioned but its not clear to me what the solution could be.

If you have another PC try it on there, so you can identify whether it is a hardware/OS issue limited to your current host.

Actually I can’t reproduce this error on my PC at the moment which is much more powerful but I did have it yesterday.
At the moment the error happens on my VPS which have multiple mt5 running. But when I check the memory during the error I don’t see any problem.. 
I’ve been developing on mql5 for a few years and it’s the first time I have this error 
 
Arthur Hatchiguian #:
Actually I can’t reproduce this error on my PC at the moment which is much more powerful but I did have it yesterday.
At the moment the error happens on my VPS which have multiple mt5 running. But when I check the memory during the error I don’t see any problem.. 
I’ve been developing on mql5 for a few years and it’s the first time I have this error 

It seems quite rare when searching MQL.com for heap or heapmin - searching for  MemoryException yields more hits but there's a lot to read!

I guess if you have many instances of mt5 running, there could be some conflict over shared memory areas and that's how you have hit the limit even though there is plenty of free RAM available. I have experienced this sort of thing with other products, but they were ERP so there were well documented options to tune them and increase the limits.


It would be down to someone with intricate knowledge of MT5 to publish whether there could be a tuning parameter which could be adjusted to overcome this, or fix it in the kernel if this is the case. 

If its your code, you could also review how efficiently you are using memory and whether there are large objects, arrays, datasets etc. you could clear down once they are no longer relevant,  or excessive recursion/looping/sorts, etc., just in case that does the trick

 
R4tna C #:

It seems quite rare when searching MQL.com for heap or heapmin - searching for  MemoryException yields more hits but there's a lot to read!

I guess if you have many instances of mt5 running, there could be some conflict over shared memory areas and that's how you have hit the limit even though there is plenty of free RAM available. I have experienced this sort of thing with other products, but they were ERP so there were well documented options to tune them and increase the limits.


It would be down to someone with intricate knowledge of MT5 to publish whether there could be a tuning parameter which could be adjusted to overcome this, or fix it in the kernel if this is the case. 

If its your code, you could also review how efficiently you are using memory and whether there are large objects, arrays, datasets etc. you could clear down once they are no longer relevant,  or excessive recursion/looping/sorts, etc., just in case that does the trick

What means ERP please?

About memory management i'm not sure what are the best practices. I use arrays of indicators for example. 


Thanks for your help by the way.

 
Arthur Hatchiguian #:

What means ERP please?

About memory management i'm not sure what are the best practices. I use arrays of indicators for example. 


Thanks for your help by the way.

Sorry - industry term for "Enterprise Resource Planning" software. Usually used by large corporations so very heavily engineered with lots of tunable parameters

https://en.wikipedia.org/wiki/Enterprise_resource_planning

Happy to help, although I am not sure I got you closer to a solution...