Sign in to follow this  
Followers 0
Yaerox

AutoIt causes memory leak?

18 posts in this topic

#1 ·  Posted (edited)

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



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

How? ^.^

Share this post


Link to post
Share on other sites

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

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

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

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

#8 ·  Posted (edited)

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

#9 ·  Posted (edited)

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

#10 ·  Posted (edited)

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

#11 ·  Posted (edited)

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

#12 ·  Posted (edited)

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

#13 ·  Posted (edited)

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

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

"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

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

#17 ·  Posted (edited)

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

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

  • Similar Content

    • P3rsp3ctiv3
      By P3rsp3ctiv3
      Hello how can I send a {Enter} into the edit window ($cmd)? I tried it first with:
      GUICtrlSetData($cmd, "Line 1" + "{ENTER}")
      but it doesn´t work. Can someone help me please?
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> $Admin = GUICreate("Admin", 234, 168, 192, 229, $GUI_SS_DEFAULT_GUI, BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE)) GUISetBkColor(0xB4B4B4) $exit = GUICtrlCreateButton("Close", 160, 136, 65, 25) $cmd = GUICtrlCreateEdit("",0, 0, 225, 137, $ES_AUTOVSCROLL + $WS_VSCROLL) GUICtrlSetData(-1, "") GUICtrlSetFont(-1, 10, 400, 0, "Candara") GUICtrlSetBkColor(-1, 0xE3E3E3) $cmd_clear = GUICtrlCreateButton("Clear", 9, 136, 65, 25) GUISetState(@SW_SHOW) HotKeySet("{f1}", CMD_1) HotKeySet("{f2}", CMD_2) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $exit GUIDelete($Admin) Exit EndSwitch WEnd Func CMD_1(); GUICtrlSetData($cmd, "Line 1" & "{ENTER}") GUICtrlSetData($cmd, "Line 2" & "{ENTER}") EndFunc Func CMD_2(); GUICtrlSetData($cmd, "Line 3" & "{ENTER}") GUICtrlSetData($cmd, "Line 4" & "{ENTER}") EndFunc
    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • AdminC
      By AdminC
      $Imglocation = @ScriptDir&"\Image\testimg.bmp" _GDIPlus_Startup() Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap) Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap) Local $imgBits = DllStructCreate('dword[' & (DllStructGetData($imgSize, 'X') * DllStructGetData($imgSize, 'Y')) & ']') _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits)) ;_WinAPI_DisplayStruct($imgBits) MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) _GDIPlus_Shutdown()  
    • AdminC
      By AdminC
      #RequireAdmin
      #include <SendMessage.au3>
      #include <WinAPI.au3>
      #include <WindowsConstants.au3>
      #include <GDIPlus.au3>
      #include <GUIConstantsEx.au3>
      #include <WinAPIGdi.au3>
      #include <Array.au3>
      #include <WinAPIDiag.au3>
      $Imglocation = @ScriptDir&"\Image\testimg.bmp"
      _GDIPlus_Startup()
      Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation)
      Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
      Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap)
      Local $imgBits = DllStructCreate('dword[' & ($imgSize.X * $imgSize.Y) & ']')
      _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits))
      _WinAPI_DisplayStruct($imgBits)
      MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) 
      _GDIPlus_Shutdown()
      DllstructGetData can't get data color B, G, R value. Who's know that? teach me plz
    • AdminC
      By AdminC
      #RequireAdmin
      #include <SendMessage.au3>
      #include <WinAPI.au3>
      #include <WindowsConstants.au3>
      #include <GDIPlus.au3>
      #include <GUIConstantsEx.au3>
      #include <WinAPIGdi.au3>
      #include <Array.au3>
      #include <WinAPIDiag.au3>
      $Imglocation = @ScriptDir&"\Image\testimg.bmp"
      _GDIPlus_Startup()
      Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation)
      Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
      Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap)
      Local $imgBits = DllStructCreate('dword[' & ($imgSize.X * $imgSize.Y) & ']')
      _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits))
      _WinAPI_DisplayStruct($imgBits)
      MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) 
      _GDIPlus_Shutdown()
      DllstructGetData can't get data color B, G, R value. Who's know that? teach me plz