LucML 0 Posted July 16, 2010 (edited) Hi all, I have a memory leak issue with my script and I can't figure out why. My script runs 24/7. As you can see there is an endless loop. After 24 to 48 h the memory usage is at 1GB and the script crash. You will not be able to run the script since it queries a software that you don't have access too. But maybe by looking at the code you can help me? See my code below. Thanks. Do WinWait("Queues") $TotalColumns = ControlListView ("Queues", "", "[CLASS:SysListView32; INSTANCE:1]", "GetSubItemCount") $TotalAgents = ControlListView ("Queues", "", 59664, "GetItemCount") FileOpen ($file, 130) Do $AgentStatus = ControlListView ("Queues", "", 59664, "GetText", $i, "0") $AgentTime = ControlListView ("Queues", "", 59664, "GetText", $i, "1") If $AgentStatus <> "" Then FileWriteLine($file, $AgentStatus & ";" & $AgentTime) EndIf $AgentStatus = "" $AgentTime = "" $i = $i + 1 Until $i = $TotalAgents $i = 0 Do $DataQueue = ControlListView ("Queues", "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", "0", $i) FileWriteLine($file, $DataQueue) $i = $i + 1 $DataQueue = "" Until $i = $TotalColumns FileClose ($file) $i = 0 Sleep (5000) $TotalColumns = "" $TotalAgents = "" Until 2 = 1 Edited July 16, 2010 by LucML Share this post Link to post Share on other sites
LucML 0 Posted July 16, 2010 (edited) Ooops I forgot a part of my script. Here is the complete script. expandcollapse popupWinWait("Queues") $i = 0 $path= "C:\inetpub\wwwroot\agentstatus\" $file= $path & "status.txt" Do WinWait("Queues") $TotalColumns = ControlListView ("Queues", "", "[CLASS:SysListView32; INSTANCE:1]", "GetSubItemCount") $TotalAgents = ControlListView ("Queues", "", 59664, "GetItemCount") FileOpen ($file, 130) Do $AgentStatus = ControlListView ("Queues", "", 59664, "GetText", $i, "0") $AgentTime = ControlListView ("Queues", "", 59664, "GetText", $i, "1") If $AgentStatus <> "" Then FileWriteLine($file, $AgentStatus & ";" & $AgentTime) EndIf $AgentStatus = "" $AgentTime = "" $i = $i + 1 Until $i = $TotalAgents $i = 0 Do $DataQueue = ControlListView ("Queues", "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", "0", $i) FileWriteLine($file, $DataQueue) $i = $i + 1 $DataQueue = "" Until $i = $TotalColumns FileClose ($file) $i = 0 Sleep (5000) $TotalColumns = "" $TotalAgents = "" Until 2 = 1 Edited July 16, 2010 by LucML Share this post Link to post Share on other sites
KaFu 295 Posted July 16, 2010 (edited) You do a FileOpen()... but don't use the handle in the subsequent operations! And finally the FileClose($file) doesn't close the opend handle, so the orphaned FileOpen() handles pile up to the sky... Do WinWait("Queues") $TotalColumns = ControlListView("Queues", "", "[CLASS:SysListView32; INSTANCE:1]", "GetSubItemCount") $TotalAgents = ControlListView("Queues", "", 59664, "GetItemCount") $hfile = FileOpen($file, 130) Do $AgentStatus = ControlListView("Queues", "", 59664, "GetText", $i, "0") $AgentTime = ControlListView("Queues", "", 59664, "GetText", $i, "1") If $AgentStatus <> "" Then FileWriteLine($hfile, $AgentStatus & ";" & $AgentTime) EndIf $AgentStatus = "" $AgentTime = "" $i = $i + 1 Until $i = $TotalAgents $i = 0 Do $DataQueue = ControlListView("Queues", "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", "0", $i) FileWriteLine($hfile, $DataQueue) $i = $i + 1 $DataQueue = "" Until $i = $TotalColumns FileClose($hfile) $i = 0 Sleep(5000) $TotalColumns = "" $TotalAgents = "" Until 2 = 1 Edited July 16, 2010 by KaFu OS: Win10-1909 - 64bit - German, AutoIt Version: 3.3.14.5, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2019-Dec-21) BIC - Batch-Image-Cropper (2019-Dec-11) COP - Color Picker (2009-May-21) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2019-Dec-07) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Share this post Link to post Share on other sites
LucML 0 Posted July 16, 2010 You Rock!!! It's working. I didn’t understand well how the fileopen is working. Now I know for next time. Thanks a bunch Share this post Link to post Share on other sites
KaFu 295 Posted July 16, 2010 You're welcome ... OS: Win10-1909 - 64bit - German, AutoIt Version: 3.3.14.5, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2019-Dec-21) BIC - Batch-Image-Cropper (2019-Dec-11) COP - Color Picker (2009-May-21) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2019-Dec-07) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Share this post Link to post Share on other sites