 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
ifckladyluck
Joined: 20 Jan 2009 Posts: 16
|
Posted: Sat Jan 24, 2009 9:41 am Post subject: getDC / getPixel memory leak |
|
|
the purpose of this script is to grey out any window whose pixel at location (6,140) is not white, and then fade it back in when it is. The script works great except for the fact that it seems to use up 4K of additional memory with every passthru. I suppose this has something to do with getDc/getPixel but I am too new at this to know for sure. I would appreciate any comments. Thank you!
| Code: |
switch := true
opacity := 100
loop
{
WinGet, tableIDList, list, ahk_class WindowClass
if numWindows <> windowIDList
refreshwindows(), numwindows := windowIDList
loop, %windowIDList%
{
windowID := windowIDList%A_Index%
hDC := windowDCList%A_Index%
pixel := DllCall("GetPixel", "Uint", hDC, "Uint", 6, "Uint", 140)
if (pixel <> 16777215) && (switch)
winset, transparent, %opacity%, ahk_id %windowID%
else
{
;winactivate, ahk_id %windowID%
winset, transparent, off, ahk_id %windowID%
}
}
sleep 500
}
refreshwindows()
{
global
loop, %windowIDList%
{
windowID := windowIDlist%A_INDEX%
windowDCList%A_Index% := DllCall("GetDC", "Uint", windowID)
}
}
|
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7295 Location: Australia
|
Posted: Sun Jan 25, 2009 1:28 am Post subject: |
|
|
| Each call to GetDC must have a corresponding call to ReleaseDC, otherwise each device context will remain in memory until the process terminates. Eventually you may run out of GDI resources, and GetDC will fail. |
|
| Back to top |
|
 |
ifckladyluck
Joined: 20 Jan 2009 Posts: 16
|
Posted: Sun Jan 25, 2009 2:39 am Post subject: |
|
|
this is true but getDC wouldnt get run very often since the numbr of windows doesnt change very frequently. the DC was meant to be kept open.
I figured out the leak it actually had to do with this line:
if numWindows <> windowIDList
this kept being evaluated as true, i think because of the tab? not sure
i changed it to
if (numWindows <> windowIDList)
and things are now kosher. thanks for the help though! |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7295 Location: Australia
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|