Sign in to follow this  
Followers 0
LucML

Memory leak

5 posts in this topic

#1 ·  Posted (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 by LucML

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by KaFu

Share this post


Link to post
Share on other sites

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

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
Sign in to follow this  
Followers 0