Metatrader 5 - Takes alot of memory when cycling a chart through symbols - page 2

 
gr101:

I put it on Windows Server 12 R2 and that also pushes the memory up.

Let me monitor this for a while and give feedback on this thread.

It's currently 650 Mb

I didn't change anything, just keep it running.

 
gr101:

Thanks for the feedback.

Think I will upgrade to Windows 10 and see if that makes a difference.

You are focusing on the loop. What else do you use in your EA? Graphical controls oder any other controls?
 

That script earlier in the thread is the full EA (ForumQuestion1.mq5), it is what pushes the memory up. There are no other actions in the EA.

No graphical controls.

 

Hi Alain,

Please see attached word doc. This is from a Windows Server 2012 R2 instance running in Windows Azure. It's a new machine (so no funny software or anything) and it's running in the Western Europe data center.

The usage memory increasing over time also happens here when running the ForumQuestion1.mq5 script (from earlier in the thread).

Here's a break down of the increase over time from 8:40am to 14:05pm it went from 74.1MB up to 379.9MB.

8:40 am

74.1 MB

 

Just started ForumQuestion1 EA

9:53 am

281.6 MB

10:30 am

297.2 MB

11:23 am

319.3 MB

12:23pm

343.5 MB

13:00 pm

369.1 MB

14:05 PM

379.9 MB

Files:
 
i think this is normal. my MT4 is on 1GB ram now
 
Daniela Bluemel:
i think this is normal. my MT4 is on 1GB ram now
This topic is about MT5 Daniela.
 
Alain Verleyen:
This topic is about MT5 Daniela.
yes i know but my MT4 has the same behaviour
 
Found a work around... it's not pretty but it works.

Solution: Run a PowerShell script that checks the memory. When it gets over 60% it restarts MetaTrader.

The script is below, I'm busy testing it.

Steps:

  1. Click Start on Windows
  2. Type "PowerShell ISE"
  3. Cut and past the script below into the text editor
  4. Press play (or save as PS1 file and run it from command prompt but I'm still testing it so running it from PowerShell ISE for now)

Script is below this restarts Metatrader (terminal64) if the memory gets over 300 MB (as per the memory column in your Task Manager):

#################################################################

strict-mode 
cls
$memoryThresholdInKiloBytes = 300000
$cooldownSeconds = 30
$loopPauseInSeconds = 30
$counter = 0

while($true){
    if($counter -gt 1000){
        cls
    }
    
    #write-host "$(get-date) Checking memory in use... counter=$counter"
    $processPrivateSet = Get-Counter "\Process(terminal64)\Working Set - Private"
    $wsPrivateKiloBytes = $processPrivateSet.CounterSamples[0].CookedValue / 1KB
   
    $memoryLabel = $wsPrivateKiloBytes.ToString('## ### ###') + " K"

    write-host "$(get-date) Kilo Bytes in use $memoryLabel"
    if($wsPrivateKiloBytes -gt $memoryThresholdInKiloBytes){
            
        write-host "$(get-date) Over threshold of $memoryLabel closing metatrader"
        
        # Close metatrader (terminal64)
        Get-Process terminal64 | Foreach-Object { 
            $_.CloseMainWindow() | Out-Null 
        } | stop-process –force
        
        # Give time to shutdown        
        write-host "$(get-date) Shutting down cooldown of $cooldownSeconds seconds #####################"
        start-sleep -Seconds $cooldownSeconds

        # Open metatrader
        write-host "$(get-date) Opening metatrader again and wait $cooldownSeconds seconds"
        &"C:\Program Files\MetaTrader 5\terminal64.exe"     
        start-sleep $cooldownSeconds
    }

    start-sleep -Seconds $loopPauseInSeconds
    $counter = $counter + 1;
}

# Links
# http://stackoverflow.com/questions/33344611/get-memory-private-working-set-of-process
 

Have you tried to setTERMINAL_MAXBARS with TerminalInfoInteger(..) to a reasonable small value?

Beside that you have:

TERMINAL_MEMORY_PHYSICAL

Physical memory in the system, Mb

int

TERMINAL_MEMORY_TOTAL

Memory available to the process of the terminal , Mb

int

TERMINAL_MEMORY_AVAILABLE

Free memory of the terminal process, Mb

int

TERMINAL_MEMORY_USED

Memory used by the terminal , Mb

int


to check where's the crux of the matter.

 

My 2 cents is that you are not freeing memory with "delete symbols" alone.

Try this:

delete symbols;
symbols=NULL;