Memory leak in Tester with MT4 build 224?

 

I'm running optimizations and the Tester crashes after about an hour. After investigation I've noticed the log file full of memory allocation errors.... I tried running optimization again, this time I left the task manager (windows xp sp3) open on the performance tab. The PF graph is a nice linear line going up very slowly.... Is this a memory leak? I have no ArrayResize() or any kind of dynamic memory allocation in my code, so I don't see how this could be from my code... Does anybody know anything about this problem?

 
I've further investigated the subject. I've used Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) to check how much memory terminal.exe is using. I've noticed that the memory graph goes up linearly while optimization is progressing. But when I press STOP to stop the optimization, memory is NOT CLEARED!!! Furthermore, if I change the inputs and press START again, so the Tester starts a new optimization, the graph continues to go up from the last point... so memory is never cleared, just builds up. This must be a memory leak??? Anybody knows anything about this?
 
gordon:
I've further investigated the subject. I've used Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) to check how much memory terminal.exe is using. I've noticed that the memory graph goes up linearly while optimization is progressing. But when I press STOP to stop the optimization, memory is NOT CLEARED!!! Furthermore, if I change the inputs and press START again, so the Tester starts a new optimization, the graph continues to go up from the last point... so memory is never cleared, just builds up. This must be a memory leak??? Anybody knows anything about this?

I found the problem... Any usage of recursive function calls causes the Tester/Optimizer to build up memory. This memory is not freed when a simulation/optimization ends so obviously IT IS A MEMORY LEAK. The only way to free the memory is to completely shut down MT4. The funny thing is that the memory keeps building up regardless of if the recursive call is actually called. Even if u have a recursive function call in a part of code that u know FOR SURE is never called - the Tester/Optimizer would still take more and more memory on each pass. I have searched the documentation and found no mention of recursive calls not allowed in MQL4 coding...


MetaQuotes - please fix this! There are certain coding situations were a recursive function call gives a much more elegant solution, not to mention fewer lines of code...

 
Try to not use recursive function. Usually, it's not good idea. See also my article HTML Walkthrough Using MQL4
 
Rosh:
Try to not use recursive function. Usually, it's not good idea. See also my article HTML Walkthrough Using MQL4

Well, I know that now. But I still see it as a bug in the Tester. When optimization is finished (or when u press "Stop" in the middle"), memory should be cleared automatically no matter what's in the code. I think the documentation should state clearly the limitations and problems using recursive calls in MQL4. It took me quite a few hours to pinpoint the problem...

 
gordon:

Well, I know that now. But I still see it as a bug in the Tester. When optimization is finished (or when u press "Stop" in the middle"), memory should be cleared automatically no matter what's in the code. I think the documentation should state clearly the limitations and problems using recursive calls in MQL4. It took me quite a few hours to pinpoint the problem...

MetaTrader 4 and MetaTrader5 both have a memory leak, I noticed it when wiriting a .Net API for MetaTrader. At first I thought it was my code so I downloaded a fresh copy of MT4 and a copy of MT5.

First I run them, no EA's nothing (virgin copies) checking the memory usage in task manager the same slow memory leak in both.

I then decided to check other copies of MT4 exactly the same!, 7 different copies from different brokers all have exactly the same memory leak.

When running tasks of any kind the leak gets worse, which is probably why recursive functions blow up, its not the recursion at fault its just exaggerating the problem that is already there.

 
This memory is not freed when a simulation/optimization ends so obviously IT IS A MEMORY LEAK

Are you putting objects on the chart, that includes the open to close lines drawn by the tester. Those are not removed until you close the chart. Likewise the hidden indicators called by the EA are also still there (I think.) Try setting bars in chart to 1000.

Are you certain you are not writing to arrays outside of their size (especially indicators) That can mess memory management.

And there could be a bug in recursive calls, I haven't use them.

Reason: