question

Serge A avatar image
6 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)

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

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

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

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:

  1. ^!r:: ; on Ctrl-Alt-R click Reset repeatedly
  2. CoordMode Client
  3. ImageSearch ResetLocX, ResetLocY, 0, 0, 300, 200, flexsim_Reset.png
  4. if (ErrorLevel = 0) {
  5.   Loop {
  6.     ClickX := ResetLocX + 30
  7.     ClickY := ResetLocY + 10
  8.     MouseMove, ClickX, ClickY
  9.     MouseClick
  10.     MouseMove, ClickX+25, ClickY+15
  11.     Sleep, 1000
  12.   }
  13. }
  14.  
  15. Esc::ExitApp ; stop on Esc
  16.  
  17. 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.