Jump to content

Almost all Autoit scripts are consuming small additional memory over time?


MDCT
 Share

Recommended Posts

Since the question is more about how exactly Autoit works, it is intended for the Autoit experts or developers.

Hello Autoit gods and goddesses,

I've just realized that almost all Autoit scripts are taking additional RAM over time. I want to know this happens on my PC only or is it made on purpose.

On my PC, Autoit scripts are taking 4kb - 16kb of RAM each time new window is active or sometime when I switching between old windows. Will this behavior stop over time maybe after 5 days after the scripts run? Or will it keeps happening all the time?

Below are the examples:

#include <winapi.au3>
For $i=1 to 2 step 0
Sleep(150)
$Result=_Check()
ConsoleWrite($Result&@CRLF)
Next
Func _Check()
Dim $Struct, $hPoint, $FPointWinTitle
$Struct = DllStructCreate($tagPoint)
DllStructSetData($Struct, "x", MouseGetPos(0))
DllStructSetData($Struct, "y", MouseGetPos(1))
$hPoint = _WinAPI_WindowFromPoint($Struct)
$FPointWinTitle=_WinAPI_GetWindowText($hPoint)
return $FPointWinTitle
EndFunc
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Dim $item[6]
GUICreate("listview items", 300, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)
$listview = GUICtrlCreateListView("col1     |col2      |col3 ", 10, 10, 200, 150, -1, $LVS_EX_CHECKBOXES)
$button = GUICtrlCreateButton("Get What Names Are Checked?", 75, 170, 170, 20)
$item[1] = GUICtrlCreateListViewItem("item1|col22|col23", $listview)
$item[2] = GUICtrlCreateListViewItem("item2|col12|col13", $listview)
$item[3] = GUICtrlCreateListViewItem("item3|c3332|col33", $listview)
$item[4] = GUICtrlCreateListViewItem("item4|44444|col33", $listview)
$item[5] = GUICtrlCreateListViewItem("item5|5555|col33", $listview)
GUISetState()
Do
$msg = GUIGetMsg()
Select
  Case $msg = $button
   For $x = 1 To 5
    If _GUICtrlListView_GetItemChecked($listview, $x - 1) Then
     MsgBox(0, "listview item", _GUICtrlListView_GetItemTextString($listview, $x - 1) & "    " & @CRLF & "Line Checked = " & $x, 2)
    EndIf
   Next
  Case $msg = $listview
   MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
EndSelect
Until $msg = $GUI_EVENT_CLOSE
As you can see, the scripts are different in functions. On my PC, those above scripts will consume RAM when I switch between new windows. As I said it is about 4kb - 16kb, not that big, but still it is not a good behavior especially it should have nothing to do with windows creation or switching.

Now, if I only use _WinAPI_WindowFromPoint, the RAM is stable, eventho I open new window, switching, etc. Below is the example code:

#include <winapi.au3>
For $i=1 to 2 step 0
Sleep(150)
$Result=_Check()
ConsoleWrite($Result&@CRLF)
Next
Func _Check()
Dim $Struct, $hPoint, $FPointWinTitle
$Struct = DllStructCreate($tagPoint)
DllStructSetData($Struct, "x", MouseGetPos(0))
DllStructSetData($Struct, "y", MouseGetPos(1))
$hPoint = _WinAPI_WindowFromPoint($Struct)
;~ $FPointWinTitle=_WinAPI_GetWindowText($hPoint)
return $hPoint
EndFunc

As you can see, I commented out the _WinAPI_GetWindowText and the script becomes stable. It doesn't take additional RAM at all.

If this is a normal behavior, what is the fix, so my scripts would be like when I use only _WinAPI_WindowFromPoint (doesn't take additional RAM over time)?

Thank you.

Link to comment
Share on other sites

I had this in my script bank, I don't know who made memoryreduce and sedebug, but I put them together some time ago and saved it.

#RequireAdmin
_SEDEBUG()
While 1
$list = ProcessList()
For $i = 1 To $list[0][0]
  _ReduceMem($list[$i][1])
Next
sleep(30000)
WEnd
Func _ReduceMem($PID = @AutoItPID)
Local $handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $PID)
DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $handle[0])
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $handle[0])
$MTim = TimerInit()
EndFunc   ;==>_ReduceMem

Func _SEDEBUG()
Local $tagLUIDANDATTRIB = "int64 Luid;dword Attributes"
Local $count = 1
Local $tagTOKENPRIVILEGES = "dword PrivilegeCount;byte LUIDandATTRIB[" & $count * 12 & "]" ; count of LUID structs * sizeof LUID struct
Local $TOKEN_ADJUST_PRIVILEGES = 0x20
Local $SE_PRIVILEGE_ENABLED = 0x2
Local $curProc = DllCall("kernel32.dll", "ptr", "GetCurrentProcess")
Local $call = DllCall("advapi32.dll", "int", "OpenProcessToken", "ptr", $curProc[0], "dword", $TOKEN_ADJUST_PRIVILEGES, "ptr*", "")
If Not $call[0] Then Return False
Local $hToken = $call[3]
$call = DllCall("advapi32.dll", "int", "LookupPrivilegeValue", "str", "", "str", "SeDebugPrivilege", "int64*", "")
Local $iLuid = $call[3]
Local $TP = DllStructCreate($tagTOKENPRIVILEGES)
Local $LUID = DllStructCreate($tagLUIDANDATTRIB, DllStructGetPtr($TP, "LUIDandATTRIB"))
DllStructSetData($TP, "PrivilegeCount", $count)
DllStructSetData($LUID, "Luid", $iLuid)
DllStructSetData($LUID, "Attributes", $SE_PRIVILEGE_ENABLED)
$call = DllCall("advapi32.dll", "int", "AdjustTokenPrivileges", "ptr", $hToken, "int", 0, "ptr", DllStructGetPtr($TP), "dword", 0, "ptr", 0, "ptr", 0)
DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hToken)
Return ($call[0] <> 0) ; $call[0] <> 0 is success
EndFunc   ;==>_SEDEBUG
Edited by THAT1ANONYMOUSEDUDE
Link to comment
Share on other sites

I had this in my script bank, I don't know who made memoryreduce and sedebug, but I put them together some time ago and saved it.

If you keep running this on a script with a memory leak you will see your pagefile usage going up and up assuming you have task manager set to show it.

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...