AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

getDC / getPixel memory leak

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ifckladyluck



Joined: 20 Jan 2009
Posts: 16

PostPosted: Sat Jan 24, 2009 9:41 am    Post subject: getDC / getPixel memory leak Reply with quote

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
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Sun Jan 25, 2009 1:28 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
ifckladyluck



Joined: 20 Jan 2009
Posts: 16

PostPosted: Sun Jan 25, 2009 2:39 am    Post subject: Reply with quote

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
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Sun Jan 25, 2009 2:47 am    Post subject: Reply with quote

Ah. FAQ: When exactly are variable names enclosed in percent signs?
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group