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

    • bowker
      By bowker
      Hi! Is there a way for me to set the value for my slider? I am getting the value for my slider with
       
      Local $strText = _UIA_getPropertyValue($oUIElement, $UIA_LegacyIAccessibleValuePropertyId) MsgBox(0,"",$strText)  
    • nacerbaaziz
      By nacerbaaziz
      Hello
      Can we pause and resume the download in the InetGet function?
      If is possible, what is the solution please?
      I used this code To manage the download

      #include <INet.au3> func _downloader($name, $linc, $filepath, $RTLF = false, $link = false) global $downloader = GUICreate("downloader", 400, 200, -1, -1, $WS_CLIPCHILDREn, $RTLF, $link) global $path = $filePath $labelTxt = GUICtrlCreateLabel("downloading " & $name, 50, 10, 200, 20) global $labelTxt0 = GUICtrlCreateLabel("downloaded size 0 MB " & "OF 0 MB", 50, 60, 300, 20) global $Progress = "" global $sText = ""     For $i = 1 To Random(5, 20, 1) ; Return an integer between 5 and 20 to determine the length of the string.         $sText &= Chr(Random(65, 122, 1)) ; Return an integer between 65 and 122 which represent the ASCII characters between a (lower-case) to Z (upper-case). next global $labelTxt2 = GUICtrlCreateInput("0%", 50, 80, 50, 20) _GUICtrlEdit_SetReadOnly(-1, true) GUIStartGroup("") global $beep = GUICtrlCreateCheckBox("use the progress beep notification", 150, 120, 200, 20) GUIStartGroup("") $button = GUICtrlCreateButton("Cancel', 130, 150, 180, 25, 0x01) $iIndex = 0 global $Target global $url GUIStartGroup("") global $Progress = GUICtrlCreateProgress(50, 90, 150, 20) global $Target = $filepath global $url = $linc global $path = $filepath global $hDownloadNo = _RSMWare_GetData($url, $Target) global $status = false AdlibRegister("SetProgress") global $onprogress = false, $curent = false GUISetState(@sw_Show) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button $asc = MsgBox(4132,"exit download?","if you click yes the downloading will be cancel, do you want to cancel it ?") if $asc = 6 then AdlibUnRegister("SetProgress") GUIDelete() If $hDownloadNo <> 0 Then InetClose($hDownloadNo) exitLoop endIf EndSwitch if $status = -1 then $status = 0 $hDownloadNo = _RSMWare_GetData($url, $Target) $onprogress = false $curent = false elseIf $Status = 1 then $status = $path GUIDelete() AdlibUnRegister("SetProgress") exitLoop endIf WEnd return $status endFunc Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state If $hDownloadNo <> 0 Then $state = InetGetInfo($hDownloadNo) If @error = 0 Then $infor = "downloaded size " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADREAD) / 1048576), 2) & " MB of " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) / 1048576), 2) & " MB " $onprogress = Round(Ceiling(($state[0] / $state[1]) * 100)) if not (InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) = 0) then if $onProgress <= 0 then $onProgress = 0 GUICtrlSetData($Progress, $onProgress) GUICtrlSetData($labelTxt0, $infor) GUICtrlSetData($labelTxt2, $onProgress & "%") if _isChecked($beep) then if $onprogress > $curent then beep((100 + $onprogress * 20), 100) $curent = $onprogress endIf endIf endIf If $state[2] Then If $state[3] Then InetClose($hDownloadNo) $status = 1 else InetClose($hDownloadNo) $status = -1 endIf endIf EndIf endIf EndFunc ;==>SetProgress
    • VollachR
      By VollachR
      Hi,
      I'm looking for a way to take a number value from a Row2 of a 2D array and according to this check if files that appear in rows 3-11 in the array exists.
      For example, if the number in Row2 is 5 I need to check for the files in Row 3-6 only, if it is 6 than rows 3-7 and so on.
      I thought on using a FOR loop but I have very little experience with those.
      Can you suggest the best way to do what I need?
      BTW, the files in Rows 3-11 will usually have blank value for any row above the number in Row2 (e.g. Row2 = 5 so Rows3-6 will have values but 8-11 be empty), The values I need are in Column 1 of the array, the name of the key from the INI file that the array was created from is in Column 0.
      Full Example:
      Row2 of Array:
      Col0 = Games# - Col1 = 5
      Rows3-6
      Col0 = Exe2 - Col1 = Path To File
      Col0 = Exe3 - Col1 = Path To File
      Col0 = Exe4 - Col1 = Path To File
      Col0 = Exe5 - Col1 = Path To File
      I need that if Row2 is 5 to check these above for rows if the file exists, if it was 6 then the next row as well and so on up until number 10 in Row2 as it can't go above 10.
      So basically for whatever number in Row2 from 2-10 need to check 1-9 rows from 3-11 to see if the files in Col1 exists and if any of them don't exist it should call a function that shows an error message.
      I'm pretty sure I have the first line of the for look correct:
      For $i = 1 To $aAIO[2][1] Just not sure how to continue from there, also not sure if $i should be equal 1 or 2.
      Help will be appreciated.
    • rudi
      By rudi
      Hello,
      for a script to display PDF files I'd like to simply use the default program for PDF files, so I used "ShellExecute(<pdf-file-full-path>)" to open these files.
       
      The result for *SOME* of the workstations is, that the Adobe Reader starts up with asking for its language. (English/German). When starting AcroRd32.exe through "ShellExecute()", this "choose your language" dialog is showing up *ALWAYS*.
       
      Just to have mentioned it: Process Explorer is presenting this command line, it looks the same for both, PCs with and without that question "Choose Language? [English|German]"
      "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" --channel=4680.0.860715181 --type=renderer "\\pc0009\Y_DRV_H\Daten\TIF\08\32\G000110832_Freigegeben.idw.pdf"  
      The next approach I thought of was to use Foxit Portable (instead of Acrord32.exe), started from a Network Drive, but it's starting up ugly slowly...
      So I tried to "Run()" instead to "ShellExecute()" the Adobe Reader. Now the result looks more stange, the "select your language" dialog shows up every now and then, but not always for the Win7 installations affected.
       
      If I place a "msgbox()" just in front of the "run()" command, it seems never to show this "select your language" dialog.
      If I take out this MsgBox() the "select your language" dialog shows up sometimes.
      When I "ClipPut()" the run command prior the "Run()" and paste that one to a CMD box, then it seems to *NEVER* happen, that this "select your language" dialog shows up.
       
      "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" "\\pc0009\Y_DRV_H\Daten\TIF\08\32\G000110832_Freigegeben.idw.pdf" $AcroRead='"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"' $PDF='"Y:\Temp\DRV_H\Daten\TIF\33\85\153385_Freigegeben.dwg.pdf"' MsgBox(0,"Values",$AcroRead & @CRLF & $PDF,1) $MyCommand=$AcroRead & " " & $PDF ClipPut($MyCommand) Run($MyCommand)  
      It looks like, that this "--channel=... --type=renderer" parameters are always fact for the AcroRd32.exe instance, that is opening the PDF to be displayed. The Instance opening the "PDF Display GUI" seems to always be a child process of another AcroRd32.exe process.
       
      Any clue, what's going on "backstage" here? How to avoid this "Choose your language" dialog? Or maybe someone can mention a different "portable" PDF viewer, I could use for this purpose?  
      Any suggestions appreciated, regards, Rudi.
×