Jump to content
Sign in to follow this  
Yaerox

AutoIt causes memory leak?

Recommended Posts

Yaerox

Hey guys,

im writing on my project and got some memory leaks. Actual im looking for the leak for a month and now i got some curios results.

I wrote some testscripts, to see, if AutoIt causes memory leaks. So i wrote some testscript for Listviews, Lists, and Labels to see, if i create a Listview with lets say 1000 items and delete them, does AutoIt reset the complete memory of these items? i'd say no. I did some tests and got the result that in best case 4K memory is missing ...

Testscript #1: Listview created by nature func in combination with UDF funcs to create and delete items.

#include
#include
#include

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

Local $hGUI = GUICreate("GUI", 500, 500)
Local $hListview = GUICtrlCreateListView("Column 1", 10, 50, 480, 440)
Local $hButton1 = GUICtrlCreateButton("Create 100 Items", 10, 10, 100, 30)
Local $hButton2 = GUICtrlCreateButton("Delete All Items", 120, 10, 100, 30)

GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($hButton1, "_create_items")
GUICtrlSetOnEvent($hButton2, "_delall_items")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

While 1
Sleep(100)
WEnd

Func _create_items()
For $i = 0 To 100
_GUICtrlListView_AddItem($hListview, Random(0, 2000))
Next
EndFunc

Func _delall_items()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListview))
EndFunc

Func _exit()
Exit
EndFunc

Testscript #2: Listview created by UDFfunc in combination with UDF funcs to create and delete items.

#include
#include
#include

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

Local $hGUI = GUICreate("GUI", 500, 500)
local $hListview = _GUICtrlListView_Create($hGUI, "Column 1", 10, 50, 480, 440)
Local $hButton1 = GUICtrlCreateButton("Create 100 Items", 10, 10, 100, 30)
Local $hButton2 = GUICtrlCreateButton("Delete All Items", 120, 10, 100, 30)

GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($hButton1, "_create_items")
GUICtrlSetOnEvent($hButton2, "_delall_items")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")


While 1
Sleep(100)
WEnd

Func _create_items()
For $i = 0 To 100
_GUICtrlListView_AddItem($hListview, Random(0, 2000))
Next
EndFunc

Func _delall_items()
_GUICtrlListView_DeleteAllItems($hListview)
EndFunc

Func _exit()
Exit
EndFunc

Testscript #3: Creating a list

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

Local $hGUI = GUICreate("GUI", 500, 500)
Local $hList = GUICtrlCreateList("Column 1", 10, 50, 480, 440)
Local $hButton1 = GUICtrlCreateButton("Create 100 Items", 10, 10, 100, 30)
Local $hButton2 = GUICtrlCreateButton("Delete All Items", 120, 10, 100, 30)

GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($hButton1, "_create_items")
GUICtrlSetOnEvent($hButton2, "_delall_items")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

While 1
Sleep(100)
WEnd

Func _create_items()
For $i = 0 To 100
GUICtrlSetData($hList, Random(0, 2000))
Next
EndFunc

Func _delall_items()
GUICtrlSetData($hList, "")
EndFunc

Func _exit()
Exit
EndFunc

Testscript #4: Working with labels.

#include
#include
#include

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

Local $hGUI = GUICreate("GUI", 500, 500)
Local $hlabel = GUICtrlCreateLabel("AP's: ", 10, 45, 100, 440)
Local $hlabel2 = GUICtrlCreateLabel("AP's: ", 110, 45, 100, 440)
Local $hlabel3 = GUICtrlCreateLabel("AP's: ", 210, 45, 100, 440)
Local $hlabel4 = GUICtrlCreateLabel("AP's: ", 310, 45, 100, 440)
Local $hlabel5 = GUICtrlCreateLabel("AP's: ", 410, 45, 100, 440)
Local $hButton1 = GUICtrlCreateButton("Create 100 Items", 10, 10, 100, 30)
Local $hButton2 = GUICtrlCreateButton("Delete All Items", 120, 10, 100, 30)

GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($hButton1, "_create_items")
GUICtrlSetOnEvent($hButton2, "_delall_items")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

While 1
Sleep(100)
WEnd

Func _create_items()
Local $sMsg = ""
Local $sMsg2 = ""
Local $sMsg3 = ""
Local $sMsg4 = ""
Local $sMsg5 = ""

For $i = 0 To 30
$sMsg = $sMsg & Random(1,200) & @CR
$sMsg2 = $sMsg2 & Random(1,200) & @CR
$sMsg3 = $sMsg3 & Random(1,200) & @CR
$sMsg4 = $sMsg4 & Random(1,200) & @CR
$sMsg5 = $sMsg5 & Random(1,200) & @CR
Next

GUICtrlSetData($hlabel, $sMsg)
GUICtrlSetData($hlabel2, $sMsg2)
GUICtrlSetData($hlabel3, $sMsg3)
GUICtrlSetData($hlabel4, $sMsg2)
GUICtrlSetData($hlabel5, $sMsg3)
EndFunc

Func _delall_items()
GUICtrlSetData($hlabel, "")
GUICtrlSetData($hlabel2, "")
GUICtrlSetData($hlabel3, "")
GUICtrlSetData($hlabel4, "")
GUICtrlSetData($hlabel5, "")
EndFunc

Func _exit()
Exit
EndFunc

Got someone a statements for me, if its true?

Regards

Looked up here: http://www.google.com

(Also tried to find out if ShellExecute causes problems)

and some more...

Edited by MikeWenzel

Share this post


Link to post
Share on other sites
FireFox

Workaround: you can free the process memory after deleting some items.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Yaerox

How? ^.^

Share this post


Link to post
Share on other sites
FireFox

Func _SelfReduceMemory()
     DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)
EndFunc   ;==>_SelfReduceMemory


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Yaerox

Garbage Collector ... since the following post, im a bit scared of using EmptyWorkingSet ...

ReduceMemory doesn't reduce the memory used, it just pages it to the hard drive, so it's an artificial reduction in memory. Calling it every 5 seconds is pointless, figure out where your memory leak is coming from before you start trying to find workarounds to bad code.

It's like you're building a house on mud, every day it sinks a little bit more unless you jack it up, you're not fixing the problem you're just fixing the symptom, the house is still sinking only you don't see that it's happening anymore. Out of sight out of mind is not good coding practice.

Share this post


Link to post
Share on other sites
FireFox

Bad workaround then.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Yaerox

I mean for me it looks like where you want to use it. On this Testscripts ofc it works well, but e.g. i got a memory leak on my project, the reason why i looked up if Listviews are leaking, im running my script 24/7. With Garbage Collector its still rising i think, it just needs more time. So ... :/ im still working around too, maybe someone else got an idea? ^^

Share this post


Link to post
Share on other sites
FireFox

No, this was a workaround for high memory, but not for memory leak.

e.g : I load a 1mib db on an array, the process takes 70mib of memory; after reducing the memory I have 3mib.

I doubt that devs forgot to delete an object/release a ressource in the functions you are using; but AutoIt is not perfect.

Edit : for your label examples, you are not deleting labels, you are just editing it's content which is not significant.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Yaerox

But e.g. on my label_script, why the memory usage isnt going back after clicking the _delall_items button? In my opinion there have to be a way to free the memory ...

I said: "i got a memory leak on my project" but i meant, everyone is telling me i had a memory leak because my memory is rising. I think its an AutoIt mistake, therefore my testscripts ...

#Edit: If you use the Testscript #1 and create 4000 Items, Delete them waiting and looking whats up with your memory, you can see that virtual memory is rising then ... i think this DllCall can hold down memory, but its no solution for this maybe existing problem of AutoIt :/

Edited by MikeWenzel

Share this post


Link to post
Share on other sites
KaFu

Well, I would say you've already got the answer in your initial post:

It seems to me that the standard functions use the lparam parameter to store a pseudo controlid (I've always wondered how that is done :) ). So the functions are good for quick coding, but not so good for 24/7 code. As Rover said, use the UDF functions for Listview and the mem leak should be gone.

Edit:

Adjusted your example #2 a bit and everything seems fine to me.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
Local $hGUI = GUICreate("GUI", 500, 500)
Local $hListview = _GUICtrlListView_Create($hGUI, "Column 1", 10, 50, 480, 440)
Local $hButton1 = GUICtrlCreateButton("Create 100 Items", 10, 10, 100, 30)
Local $hButton2 = GUICtrlCreateButton("Delete All Items", 120, 10, 100, 30)
GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($hButton1, "_create_items")
GUICtrlSetOnEvent($hButton2, "_delall_items")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
for $i = 0 to 100
_create_items()
Sleep(1000)
_delall_items()
Next
While 1
Sleep(100)
WEnd
Func _create_items()
_GUICtrlListView_BeginUpdate($hListview)
For $i = 0 To 10000
_GUICtrlListView_AddItem($hListview, Random(0, 2000))
Next
_GUICtrlListView_EndUpdate($hListview)
EndFunc ;==>_create_items
Func _delall_items()
_GUICtrlListView_BeginUpdate($hListview)
_GUICtrlListView_DeleteAllItems($hListview)
_GUICtrlListView_EndUpdate($hListview)
EndFunc ;==>_delall_items
Func _exit()
Exit
EndFunc ;==>_exit

Edit #2:

Nevertheless the mem leak in the default function is definitly worth a bug ticket!

Edit #3:

Here's a little more aggressive example. I've added _GUICtrlListView_SetItemCount($hListview, 0), as this was suggested to be used explicitly in some google results.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
Local $hGUI = GUICreate("GUI", 500, 500)
Local $hListview = _GUICtrlListView_Create($hGUI, "Column 1", 10, 50, 480, 440)
Local $hButton1 = GUICtrlCreateButton("Create 100 Items", 10, 10, 100, 30)
Local $hButton2 = GUICtrlCreateButton("Delete All Items", 120, 10, 100, 30)
GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($hButton1, "_create_items")
GUICtrlSetOnEvent($hButton2, "_delall_items")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
For $i = 1 To 10000
ConsoleWrite($i & @CRLF)
_create_items()
_delall_items()
Next
While 1
Sleep(100)
WEnd

Func _create_items()
_GUICtrlListView_BeginUpdate($hListview)
_GUICtrlListView_SetItemCount($hListview, 100)
For $i = 1 To 100
_GUICtrlListView_AddItem($hListview, Random(0, 2000))
Next
_GUICtrlListView_EndUpdate($hListview)
EndFunc ;==>_create_items
Func _delall_items()
_GUICtrlListView_BeginUpdate($hListview)
_GUICtrlListView_DeleteAllItems($hListview)
_GUICtrlListView_SetItemCount($hListview, 0)
_GUICtrlListView_EndUpdate($hListview)
EndFunc ;==>_delall_items
Func _exit()
Exit
EndFunc ;==>_exit
Edited by KaFu

Share this post


Link to post
Share on other sites
Yaerox

Did it this way:

#include
#include

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

Local $hGUI = GUICreate("GUI", 500, 500)
Local $hListview = _GUICtrlListView_Create($hGUI, "Column 1", 10, 50, 480, 440)
Local $hButton1 = GUICtrlCreateButton("Create 10000 Items", 10, 10, 100, 30)
Local $hButton2 = GUICtrlCreateButton("Delete All Items", 120, 10, 100, 30)

GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($hButton1, "_create_items")
GUICtrlSetOnEvent($hButton2, "_delall_items")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

;~ For $i = 0 To 100
;~ _create_items()
;~ Sleep(1000)
;~ _delall_items()
;~ Next

While 1
Sleep(100)
WEnd

Func _create_items()
_GUICtrlListView_BeginUpdate($hListview)
For $i = 0 To 10000
_GUICtrlListView_AddItem($hListview, Random(0, 2000))
Next
_GUICtrlListView_EndUpdate($hListview)
EndFunc ;==>_create_items

Func _delall_items()
_GUICtrlListView_BeginUpdate($hListview)
_GUICtrlListView_DeleteAllItems($hListview)
_GUICtrlListView_EndUpdate($hListview)
EndFunc ;==>_delall_items

Func _exit()
Exit
EndFunc ;==>_exit

My Result:

11.228K start

12.852K clicked create once

11.600K clicked del

11.500K (waited a few mins)

12.760K clicked create once

11.736K clicked create once

12.784K clicked create once

11.648K clicked create once

15.998K clicked create 3 times

12.132K clicked create once

Edited by MikeWenzel

Share this post


Link to post
Share on other sites
KaFu

Hmmm, mem leaks are sometime hard to detect, doing some few manual tests are imho not sufficient. Maybe give my second example a try, increase the loop count to 100.000 and see how mem usage develops over a longer time (esp. the setitemcount might have an effect too).

Edit:

100 16.648

1000 16.972

3000 16.972

4000 16.972

5000 16.972

7000 16.976

9000 16.976

10000 16.972

19000 16.996

26000 17.032

30000 17.032

50000 17.036

63000 17.040

100000 17.040

Well, mem usage is increasing slighlty over time, but I would not say this is really a mem leak.

Edited by KaFu

Share this post


Link to post
Share on other sites
Yaerox

Did it with your script - loop count to 100, now starting a second try with 100000 too...

Edited by MikeWenzel

Share this post


Link to post
Share on other sites
kylomas

Mike,

The following might be usefull as a template to measure mem resource usage, varying the controls as you like. It is setup to run the control add/delete every 3 seconds and report memory usage every 10 seconds.

Use the ESC key to exit.

#include <guiconstants.au3>
#include <windowsconstants.au3>
#include <guilistview.au3>
#include <winapiex.au3>
#include <date.au3>

local $gui010   =   guicreate('ListView Mem Test - UDF')
local $aSize    =   wingetclientsize($gui010)
local $lst010   =   _GUICtrlListView_Create($gui010,'Test',0,0,$aSize[0],$aSize[1])
                    guisetstate()

                    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
                    adlibregister('_excercise',3000)
                    adlibregister('_logmem',10000)

local $fl_name = @scriptdir & 'memstats.txt'

_logmem()   ; memory usage at start

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
    EndSwitch
WEnd

func _excercise()

    for $1 = 0 to 9999
        _GUICtrlListView_AddItem($lst010,'Entry # ' & $1)
    Next

    _GUICtrlListView_DeleteAllItems($lst010)

EndFunc

func _logmem()

    local $hfl = fileopen($fl_name,1)
    if $hfl = -1 then msgbox(0,'Memstats File Open Error','File Name = ' & $fl_name)

    local $aMem = _winapi_getprocessmemoryinfo()

    filewrite($hfl, _now() & stringformat( _
                        'Page faults  = %010i ' & _
                        'Peak WS Size = %010i ' & _
                        'Current WS Size = %010i '  & _
                        'Peak Page Pool Usage = %010i '  & _
                        'Cur Page Pool Usage = %010i '  & _
                        'Peak non-Paged Pool Usage = %010i '  & _
                        'Cur non-Paged Pool Usage = %010i '  & _
                        'Cur Page file Alloc = %010i '  & _
                        'Peak Page file Alloc = %010i '  & _
                        'Current Private Space = %010i ' _
                        , $aMem[0], $aMem[1], $aMem[2], $aMem[3], $aMem[4], $aMem[5], $aMem[6], $aMem[7], $aMem[8], $aMem[9]) & @lf)

    fileclose($hfl)
    $hfl = 0

endfunc

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
     If BitAND($wParam, 0x0000FFFF) =  2 then exit
 EndFunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
lorenkinzel

"ReduceMemory doesn't reduce the memory used, it just pages it to the hard drive"

1) I am not qualified to disagree with BrewManNH

2) I am running xpsp3 with no paging

3) empty working set (ReduceMemory) works fine for me. --Shows in process manager & in speed of large ram-sucking processes

I have over-used 'ReduceMemory' & got diminished benifits (near zero) with abuse. Monoceres feels it causes trouble with angels (if abused).

If ReduceMemory only sends the mem page to hard drive, then why does it work so nicely with no paging?

I think that it is a good thing to have (ReduceMemory) at the beginning (only) of a script.

4) refer to .... 1)

Share this post


Link to post
Share on other sites
trancexx

I have closed a bug report #2291 by this user because I see no leakage. If someone could write simple reproducer that I can run that would show the leak, that would be super. Thanks in advance.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Yaerox

Fist of all sry for my late answer, i had no chance to work on it at the Weekend.

@KaFu: Script started on Friday around ~12MB Private Space. After 100.000 loops, the Private Space (today) was around ~14MB ...

@kylomas: Thanks alot for this script. I was looking for it for two weeks :P Did this on your Script (modified a bit):

#include
#include
#include
#include
#include

local $gui010 = guicreate('ListView Mem Test - UDF')
local $aSize = wingetclientsize($gui010)
local $lst010 = _GUICtrlListView_Create($gui010,'Test',0,0,$aSize[0],$aSize[1])
guisetstate()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
adlibregister('_excercise',3000)
adlibregister('_logmem',10000)

local $fl_name = @scriptdir & 'memstats.txt'

_logmem() ; memory usage at start

while 1
switch guigetmsg()
case $gui_event_close
AdlibUnRegister('_excercise')
AdlibUnRegister('_logmem')
Sleep(3000)

$aMem = 0
_logmem() ; memory usage at end
Exit
EndSwitch
WEnd

func _excercise()

for $1 = 0 to 9999
_GUICtrlListView_AddItem($lst010,'Entry # ' & $1)
Next

_GUICtrlListView_DeleteAllItems($lst010)

EndFunc

func _logmem()

local $hfl = fileopen($fl_name,1)
if $hfl = -1 then msgbox(0,'Memstats File Open Error','File Name = ' & $fl_name)

local $aMem = _winapi_getprocessmemoryinfo()

filewrite($hfl, "[" & _now() & "] " &stringformat( _
'Page faults = %010i ' & _
'Peak WS Size = %010i ' & _
'Current WS Size = %010i ' & _
'Peak Page Pool Usage = %010i ' & _
'Cur Page Pool Usage = %010i ' & _
'Peak non-Paged Pool Usage = %010i ' & _
'Cur non-Paged Pool Usage = %010i ' & _
'Cur Page file Alloc = %010i ' & _
'Peak Page file Alloc = %010i ' & _
'Current Private Space = %010i ' _
, $aMem[0], $aMem[1], $aMem[2], $aMem[3], $aMem[4], $aMem[5], $aMem[6], $aMem[7], $aMem[8], $aMem[9]) & @lf)

fileclose($hfl)
$hfl = 0

endfunc

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
If BitAND($wParam, 0x0000FFFF) = 2 Then
AdlibUnRegister('_excercise')
AdlibUnRegister('_logmem')
Sleep(3000)
$aMem = 0
_logmem() ; memory usage at end
Exit
EndIf
EndFunc

And got:

[17.12.2012 08:33:17] Page faults = 0000007107 Peak WS Size = 0027602944 Current WS Size = 0027602944 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000201920 Peak non-Paged Pool Usage = 0000013272 Cur non-Paged Pool Usage = 0000013272 Cur Page file Alloc = 0021643264 Peak Page file Alloc = 0021643264 Current Private Space = 0021643264
[17.12.2012 08:33:29] Page faults = 0000008163 Peak WS Size = 0029724672 Current WS Size = 0028573696 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000201920 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000013272 Cur Page file Alloc = 0022671360 Peak Page file Alloc = 0023478272 Current Private Space = 0022671360
[17.12.2012 08:33:41] Page faults = 0000009264 Peak WS Size = 0029753344 Current WS Size = 0028733440 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000201920 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000013272 Cur Page file Alloc = 0022966272 Peak Page file Alloc = 0023478272 Current Private Space = 0022966272
[17.12.2012 08:33:53] Page faults = 0000010395 Peak WS Size = 0030113792 Current WS Size = 0028999680 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000201920 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000013272 Cur Page file Alloc = 0023109632 Peak Page file Alloc = 0024330240 Current Private Space = 0023109632
[17.12.2012 08:34:05] Page faults = 0000011583 Peak WS Size = 0030851072 Current WS Size = 0029782016 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000201920 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000013272 Cur Page file Alloc = 0024236032 Peak Page file Alloc = 0024907776 Current Private Space = 0024236032
[17.12.2012 08:34:17] Page faults = 0000012613 Peak WS Size = 0031072256 Current WS Size = 0029913088 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000201920 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000013272 Cur Page file Alloc = 0023924736 Peak Page file Alloc = 0025169920 Current Private Space = 0023924736
[17.12.2012 08:34:29] Page faults = 0000013563 Peak WS Size = 0031072256 Current WS Size = 0030044160 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000201920 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000012128 Cur Page file Alloc = 0024657920 Peak Page file Alloc = 0025169920 Current Private Space = 0024657920
[17.12.2012 08:34:41] Page faults = 0000014452 Peak WS Size = 0031072256 Current WS Size = 0029818880 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000185720 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000012008 Cur Page file Alloc = 0023719936 Peak Page file Alloc = 0025169920 Current Private Space = 0023719936
[17.12.2012 08:34:53] Page faults = 0000015385 Peak WS Size = 0031072256 Current WS Size = 0030056448 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000185720 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000012008 Cur Page file Alloc = 0024465408 Peak Page file Alloc = 0025169920 Current Private Space = 0024465408
[17.12.2012 08:35:05] Page faults = 0000016295 Peak WS Size = 0031072256 Current WS Size = 0030027776 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000185720 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000012008 Cur Page file Alloc = 0024199168 Peak Page file Alloc = 0025169920 Current Private Space = 0024199168
[17.12.2012 08:35:17] Page faults = 0000017258 Peak WS Size = 0031072256 Current WS Size = 0029904896 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000185720 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000012008 Cur Page file Alloc = 0023941120 Peak Page file Alloc = 0025169920 Current Private Space = 0023941120
[17.12.2012 08:35:29] Page faults = 0000018244 Peak WS Size = 0031117312 Current WS Size = 0030306304 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000185720 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000012008 Cur Page file Alloc = 0024256512 Peak Page file Alloc = 0025169920 Current Private Space = 0024256512
[17.12.2012 08:35:36] Page faults = 0000018499 Peak WS Size = 0031195136 Current WS Size = 0030466048 Peak Page Pool Usage = 0000203480 Cur Page Pool Usage = 0000185720 Peak non-Paged Pool Usage = 0000013752 Cur non-Paged Pool Usage = 0000012008 Cur Page file Alloc = 0024428544 Peak Page file Alloc = 0025169920 Current Private Space = 0024428544

We can see, Private Space is rising, and thats exactly my actual problem. Usually this should be the same as at the beginning if the complete memory is getting free. Doesnt it?

Regards

#Edit: @trancexx: maybe this can show my issue:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include
#include
#include
#include

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

local $fl_name = @scriptdir & 'lv_test_memstats.txt'
Local $hGUI = GUICreate("GUI", 500, 500)
local $hListview = _GUICtrlListView_Create($hGUI, "Column 1", 10, 50, 480, 440)
Local $hButton1 = GUICtrlCreateButton("Create 4000 Items", 10, 10, 100, 30)
Local $hButton2 = GUICtrlCreateButton("Delete All Items", 120, 10, 100, 30)

GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($hButton1, "_create_items")
GUICtrlSetOnEvent($hButton2, "_delall_items")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

_logmem("Begin Script")

While 1
Sleep(100)
WEnd

Func _create_items()
_logmem("Begin _Create_items")
For $i = 0 To 4000
_GUICtrlListView_AddItem($hListview, Random(0, 2000))
Next
_logmem("End _Create_items")
EndFunc

Func _delall_items()
_logmem("Begin _delall_items")
_GUICtrlListView_DeleteAllItems($hListview)
_logmem("End _delall_items")
EndFunc

func _logmem($sPos)
local $hfl = fileopen($fl_name,1)
if $hfl = -1 then msgbox(0,'Memstats File Open Error','File Name = ' & $fl_name)

local $aMem = _winapi_getprocessmemoryinfo()

filewrite($hfl, $sPos & " [" & _now() & "] " &stringformat( _
'Current Private Space = %010i ' _
, $aMem[0], $aMem[1], $aMem[2], $aMem[3], $aMem[4], $aMem[5], $aMem[6], $aMem[7], $aMem[8], $aMem[9]) & @lf)

fileclose($hfl)
$hfl = 0
endfunc

Func _exit()
_logmem("End Script")
Exit
EndFunc

[1]Begin Script [17.12.2012 09:13:46] Current Private Space =    7142
    [2]-----------------------------------------------------------------------------
    [3]Begin _Create_items [17.12.2012 09:13:48] Current Private Space = 7234
    [4]End _Create_items [17.12.2012 09:13:49] Current Private Space = 7395
    [5]Begin _delall_items [17.12.2012 09:13:50] Current Private Space = 7396
    [6]End _delall_items [17.12.2012 09:13:50] Current Private Space = 7396
    [7]Begin _Create_items [17.12.2012 09:13:51] Current Private Space = 7397
    [8]End _Create_items [17.12.2012 09:13:52] Current Private Space = 7528
    [9]Begin _delall_items [17.12.2012 09:13:52] Current Private Space = 7530
    [10]End _delall_items [17.12.2012 09:13:52] Current Private Space = 7530
    [11]Begin _Create_items [17.12.2012 09:13:57] Current Private Space = 7530
    [12]End _Create_items [17.12.2012 09:13:58] Current Private Space = 7636
    [13]Begin _delall_items [17.12.2012 09:13:58] Current Private Space = 7636
    [14]End _delall_items [17.12.2012 09:13:58] Current Private Space = 7636
    [15]-----------------------------------------------------------------------------
    [16]End Script [17.12.2012 09:14:03] Current Private Space = 7637

In my opinion the Private Space @line 6 should be the same as @line 3, doesnt it? Same @line 10 / 7, 14 / 11.

Edited by MikeWenzel

Share this post


Link to post
Share on other sites
guwguw

When using Scite (I'm not sure whether it is this or AutoIt itself) , it keeps growing its memory needs as long as Scite stays active - no matter whether a program gets closed there or not.

Because I use a lot of ConsoleWrite() calls for debugging purposes, I always assumed that the amount of text displayed (and therefore stored) is the main culprit for loss of available memory.

Like all the results from ConsoleWrite() never get erased until the program gets closed ... even in compiled *.exe s as far as I can tell.

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  

  • Similar Content

    • PuneetTewani
      By PuneetTewani
      Mouse click (using coordinates) not working on NSE NOW software. Works well everywhere else.
    • TheDcoder
      By TheDcoder
      Hello Guys! I wanted to share all my knowledge on arrays! Hope may enjoy the article , Lets start!
      Declaring arrays!
      Declaring arrays is a little different than other variables: 
      ; Rules to follow while declaring arrays: ; ; Rule #1: You must have a declarative keyword like Dim/Global/Local before the declaration unless the array is assigned a value from a functions return (Ex: StringSplit) ; Rule #2: You must declare the number of dimensions but not necessarily the size of the dimension if you are gonna assign the values at the time of declaration. #include <Array.au3> Local $aEmptyArray[0] ; Creates an Array with 0 elements (aka an Empty Array). Local $aArrayWithData[1] = ["Data"] _ArrayDisplay($aEmptyArray) _ArrayDisplay($aArrayWithData) That's it
      Resizing Arrays
      Its easy! Just like declaring an empty array! ReDim is our friend here:
      #include <Array.au3> Local $aArrayWithData[1] = ["Data1"] ReDim $aArrayWithData[2] ; Change the number of elements in the array, I have added an extra element! $aArrayWithData[1] = "Data2" _ArrayDisplay($aArrayWithData) Just make sure that you don't use ReDim too often (especially don't use it in loops!), it can slow down you program.
      Best practice of using "Enum"
      You might be wondering what they might be... Do you know the Const keyword which you use after Global/Local keyword? Global/Local are declarative keywords which are used to declare variables, of course, you would know that already by now , If you check the documentation for Global/Local there is a optional parameter called Const which willl allow you to "create a constant rather than a variable"... Enum is similar to Const, it declares Integers (ONLY Integers):
      Global Enum $ZERO, $ONE, $TWO, $THREE, $FOUR, $FIVE, $SIX, $SEVEN, $EIGHT, $NINE ; And so on... ; $ZERO will evaluate to 0 ; $ONE will evaluate to 1 ; You get the idea :P ; Enum is very useful to declare Constants each containing a number (starting from 0) This script will demonstrate the usefulness and neatness of Enums :
      ; We will create an array which will contain details of the OS Global Enum $ARCH, $TYPE, $LANG, $VERSION, $BUILD, $SERVICE_PACK Global $aOS[6] = [@OSArch, @OSType, @OSLang, @OSVersion, @OSBuild, @OSServicePack] ; Now, if you want to access anything related to the OS, you would do this: ConsoleWrite(@CRLF) ConsoleWrite('+>' & "Architecture: " & $aOS[$ARCH] & @CRLF) ConsoleWrite('+>' & "Type: " & $aOS[$TYPE] & @CRLF) ConsoleWrite('+>' & "Langauge: " & $aOS[$LANG] & @CRLF) ConsoleWrite('+>' & "Version: " & $aOS[$VERSION] & @CRLF) ConsoleWrite('+>' & "Build: " & $aOS[$BUILD] & @CRLF) ConsoleWrite('+>' & "Service Pack: " & $aOS[$SERVICE_PACK] & @CRLF) ConsoleWrite(@CRLF) ; Isn't it cool? XD You can use this in your UDF(s) or Program(s), it will look very neat!
      Looping through an Array
      Looping through an array is very easy! . There are 2 ways to loop an array in AutoIt!
      Simple Way:
      ; This is a very basic way to loop through an array ; In this way we use a For...In...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $vElement In $aArray ; $vElement will contain the value of the elements in the $aArray... one element at a time. ConsoleWrite($vElement & @CRLF) ; Prints the element out to the console Next ; And that's it! Advanced Way:
      ; This is an advanced way to loop through an array ; In this way we use a For...To...Next Loop! Global $aArray[4] = ["Foo", "Bar", "Baz", "Quack"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $i = 0 To UBound($aArray) - 1 ; $i is automatically created and is set to zero, UBound($aArray) returns the no. of elements in the $aArray. ConsoleWrite($aArray[$i] & @CRLF) ; Prints the element out to the console. Next ; This is the advanced way, we use $i to access the elements! ; With the advanced method you can also use the Step keyword to increase the offset in each "step" of the loop: ; This will only print every 2nd element starting from 0 ConsoleWrite(@CRLF & "Every 2nd element: " & @CRLF) For $i = 0 To UBound($aArray) - 1 Step 2 ConsoleWrite($aArray[$i] & @CRLF) Next ; This will print the elements in reverse order! ConsoleWrite(@CRLF & "In reverse: " & @CRLF) For $i = UBound($aArray) - 1 To 0 Step -1 ConsoleWrite($aArray[$i] & @CRLF) Next ; And that ends this section! For some reason, many people use the advance way more than the simple way . For more examples of loops see this post by @FrancescoDiMuro!
      Interpreting Multi-Dimensional Arrays
      Yeah, its the most brain squeezing problem for newbies, Imagining an 3D Array... I will explain it in a very simple way for ya, so stop straining you brain now! . This way will work for any array regardless of its dimensions...
      Ok, Lets start... You can imagine an array as a (data) mine of information:

      ; Note that: ; Dimension = Level (except the ground level :P) ; Element in a Dimension = Path ; Level 2 ----------\ ; Level 1 -------\ | ; Level 0 ----\ | | ; v v v Local $aArray[2][2][2] ; \-----/ ; | ; v ; Ground Level ; As you can see that $aArray is the Ground Level ; All the elements start after the ground level, i.e from level 0 ; Level 0 Contains 2 different paths ; Level 1 Contains 4 different paths ; Level 2 Contains 8 different paths ; When you want too fill some data in the data mine, ; You can do that like this: $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 ; Don't get confused with the 0s & 1s, Its just tracing the path! ; Try to trace the path of a number with the help of the image! Its super easy! :D I hope you might have understand how an array looks, Mapping your way through is the key in Multi-Dimensional arrays, You take the help of notepad if you want! Don't be shy!
      Frequently Asked Questions (FAQs) & Their answers
      Q #1. What are Arrays?
      A. An Array is an datatype of an variable (AutoIt has many datatypes of variables like "strings", "integers" etc. Array is one of them). An Array can store information in a orderly manner. An Array consist of elements, each element can be considered as a variable (and yes, each element has its own datatype!). AutoIt can handle 16,777,216 elements in an Array, If you have an Array with 16,777,217 elements then AutoIt crashes.
      Q #2. Help! I get an error while declaring an Array!?
      A. You tried to declare an array like this:
      $aArray[1] = ["Data"] That is not the right way, Array is a special datatype, since its elements can be considered as individual variables you must have an declarative keyword like Dim/Global/Local before the declaration, So this would work:
      Local $aArray[1] = ["Data"] Q #3. How can I calculate the no. of elements in an array?
      A. The UBound function is your answer, Its what exactly does! If you have an multi-dimensional Array you can calculate the total no. of elements in that dimension by specifying the dimension in the second parameter of UBound
      Q #4. Why is my For...Next loop throwing an error while processing an Array?
      A.  You might have done something like this:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) ; Concentrate here! $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Did you notice the mistake? UBound returns the no. of elements in an array with the index starting from 1! That's right, you need to remove 1 from the total no. of elements in order to process the array because the index of an array starts with 0! So append a simple - 1 to the statment:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) - 1 $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Q #5. Can an Array contain an Array? How do I access an Array within an Array?
      A. Yes! It is possible that an Array can contain another Array! Here is an example of an Array within an Array:
      ; An Array can contain another Array in one of its elements ; Let me show you an example of what I mean ;) #include <Array.au3> Global $aArray[2] $aArray[0] = "Foo" Global $aChildArray[1] = ["Bar"] $aArray[1] = $aChildArray _ArrayDisplay($aArray) ; Did you see that!? The 2nd element is an {Array} :O ; But how do we access it??? ; You almost guessed it, like this: ; Just envolope the element which contains the {Array} (as shown in _ArrayDisplay) with brackets (or parentheses)! :D ConsoleWrite(($aArray[1])[0]) ; NOTE the brackets () around $aArray[1]!!! They are required or you would get an syntax error! ; So this: $aArray[1][0] wont work!  
      More FAQs coming soon!
    • simonc8
      By simonc8
      I have a script which executes sleep for a couple of hours then carries out instructions. Does the running AutoIt script prevent the computer from entering sleep mode during this time? If not, is there something I can add to the AutoIt script to keep the computer awake?
      Grateful for advice.
    • gahhon
      By gahhon
      Hi,
      I have a program that is read data from the .txt file, since the .txt file is only readable, viewable and editable for the admin user.
      But how could I lock it with password, or some other technique that can helps to achieve this?
      Thanks for the advanced information.
    • gahhon
      By gahhon
      Hi,
      How can I the trigger the another button functions without waiting the previous function to finish execute?
      Any advise?
      I couldn't find any relevant topics via google.
      Thanks a lot.
×