question

Serge A avatar image
4 Likes"
Serge A asked Matthew Gillespie answered

Potential memory leak on Reset

I noticed that memory allocation of the flexsim.exe process seems to go up with Resets and possibly some other operations. Initially a user has reported that the memory is not completely freed on File -> New Model, but after some tests I came to the conclusion, that even a single Reset is enough to see some memory allocated which is not freed later.

The bigger the model, the more noticeable is this effect.

How to reproduce

1. Create a model with 1600 Operators (the effect seems to be proportional to the number of objects in the model)

for (int i = 1; i <= 40; i++) {
     for (int j = 1; j <= 40; j++) {
         Object op = createinstance(library().find("?Operator"), model());
         op.location = Vec3(-20 + j, -10 + i, 0);
         op.rotation.z = -90;
     }
 }

2. Monitor Working Set size of the flexsim.exe process. I used this PowerShell script to sample it every 5 seconds:

Set-Content .\memlog.txt -value ""
while ($true){ 
     $p = Get-Process -Name flexsim ;
     if ($p) { 
        $s = "$(Get-Date -Format 'HH:mm:ss')`t$($p.WS / 1024 / 1024)`tMiB" 
        Write-Host $s 
        Add-Content -Path memlog.txt -Value $s 
        Sleep 5 
    } 
}

3. I used this AutoHotKey script (attached reset_repeat.ahk.txt, rename as reset_repeat.ahk, and flexsim_Reset.png, save it in the same directory) to click Reset button every second:

^!r:: ; on Ctrl-Alt-R click Reset repeatedly 
CoordMode Client
ImageSearch ResetLocX, ResetLocY, 0, 0, 300, 200, flexsim_Reset.png
if (ErrorLevel = 0) {
   Loop {
     ClickX := ResetLocX + 30
     ClickY := ResetLocY + 10
     MouseMove, ClickX, ClickY
     MouseClick
     MouseMove, ClickX+25, ClickY+15
     Sleep, 1000
  }
} 

Esc::ExitApp ; stop on Esc 

return

And this is the result:

On average FlexSim is allocating 0.425 MiB per reset, or roughly 279 bytes per Operator object.

Expected behavior: WS is reaches a plateau after a number of iterations.


FlexSim 20.0.9
bugflexsim 20.0.9resetmemory leak
memlog.png (102.3 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered

Thanks for pointing this out. We'll look into it.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.