Jump to content

Memory leak


Recommended Posts

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 by LucML
Link to comment
Share on other sites

Ooops I forgot a part of my script. Here is the complete script.

WinWait("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 by LucML
Link to comment
Share on other sites

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 by KaFu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...