Memory leak when changing timeframe?

 

I drop EA onto M30 chart of window 0. EA draws Trendlines:

      QueLine="queM5-"+lastQueTimeM5+" "+pTime;
      ObjectCreate(QueLine,OBJ_TREND,0,lastQueTimeM5,lastQueTickM5,curTime,pTick);
      ObjectSet(QueLine,OBJPROP_WIDTH,2); 
      ObjectSet(QueLine,OBJPROP_STYLE,1); 
      ObjectSet(QueLine,OBJPROP_RAY,0); 
      ObjectSet(QueLine,OBJPROP_STYLE,STYLE_SOLID); 
//      ObjectSet(QueLine,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M5);

and calls Delphi DLL which is doing basic logging to disk, nothing else. All works for days:


once I click and change timeframe few times to say M5 M15 back to M30, to check in different timeframes how Trendlines are drawn, memory consumption starts going up quickly:


in few hours it grows to ~2Gb. EA's DLL reports Out of Memory exception:

10:29:03-3572 LogLine: Exception of class: "EAccessViolation" with message "Access violation at address 7C901010 in module 'ntdll.dll'. Read of address 0000001C"
10:29:03-3572 LogLine: Exception of class: "EOutOfMemory" with message "Out of memory"

When I Remove EA, memory use goes down to normal:


what's wrong with changing timeframes this way, why it affects EA so much?

What else should I do when drawing those Trendlines?

it's InstaTrader v.4.0.0 Build 432, thanks!

 
Konst9127:

in few hours it grows to ~2Gb. EA's DLL reports Out of Memory exception:



Test it without your DLL . . .
 
Are the objects released in the deinit?
 
Ickyrus:
Are the objects released in the deinit?

no, I didn't release them - it's quite handy to restart EA, while keeping previously drawn Trendlines on the chart..

is deinit() being called when changing timeframe? init() is not called, as per logs.

thanks

 

I'd have to experiment. Changing a timeframe will call a clear and redraw and refresh the chart. Thinking and typing at the same time sorry. The chart is an object with sub-oject lists attached to it. To work the refresh without creating too many errors the EA must be disabled and re-enabled. Now we step into the unknown of does the chart interupt the EA process or wait for the EA tick process to end before updating the chart and will that interupt cause memory leak (unreleased function memory stack calls).

 
Ickyrus:

I'd have to experiment. Changing a timeframe will call a clear and redraw and refresh the chart. Thinking and typing at the same time sorry. The chart is an object with sub-oject lists attached to it. To work the refresh without creating too many errors the EA must be disabled and re-enabled. Now we step into the unknown of does the chart interupt the EA process or wait for the EA tick process to end before updating the chart and will that interupt cause memory leak (unreleased function memory stack calls).


sorry, I was wrong: deinit() and init() is happening every time I change timeframe of the chart with a mouse - as per logs. So it's full EA restart.

Is any way for EA to learn in init(), what timeframe I chose with a mouse?

About chart refresh and EA tick processing: memory leak is steady over time, while I changed timeframe just 2-3 times in an hour.
 

You can pick up a few useful ideas from this article

 
Konst9127:

sorry, I was wrong: deinit() and init() is happening every time I change timeframe of the chart with a mouse - as per logs. So it's full EA restart.

Is any way for EA to learn in init(), what timeframe I chose with a mouse?


Yes, Period() . . . .

What happened when you tried your EA without your DLL ?

 
RaptorUK:


Yes, Period() . . . .

What happened when you tried your EA without your DLL ?


that's what I'm doing now - removing all calls to DLL
 
Konst9127:
no, I didn't release them - it's quite handy to restart EA, while keeping previously drawn Trendlines on the chart.
is deinit() being called when changing timeframe? init() is not called, as per logs.
  1. You didn't delete them in deinit() so every change creates a new set.
  2. Deinit() and init() are called each time. See Uninitialize reason codes - MQL4 Documentation
Reason: