I've been automating some web tasks lately using the standard COM library. I'm fairly new to COM and have been following the very helpful tutorial Tank has written here:
IE and Gui Browser Com Tutorial. Thanks for a great tutorial Tank.
I recently noticed unusually high memory usage in a scrabble player I've been working on for months now. Investigating shows me that there's a memory leak, the application just uses more and more memory as time goes on. When watching game activity vrs memory usage, it seems to be related to the postmessage commands. I was originally thinking it would be related to COM.
The application loads a game of scrabble (which is flash based) via its url, then plays the game and keeps track of the score. It plays through lots of games and catalogs the games and answers. It never leaves the page, the games are all loaded in that window. I used postmessage to interact with the flash buttons in the games. I'm using a simple gui and COM control like this:
Code:
COM_AtlAxWinInit()
Gui, +LastFound
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),0,0,1024,768, "Shell.Explorer") )
I have setup some simple functions for postmessage that look like this:
Code:
PostClick(CX, CY, WinId)
{
Global ProtectInput
If ProtectInput = 1
BlockInput, On
PostMessage, 0x200, 0x00000000, CX | CY << 16, Internet Explorer_Server1, ahk_id %WinID%
PostMessage, 0x201, 0x00000000, CX | CY << 16, Internet Explorer_Server1, ahk_id %WinID%
PostMessage, 0x202, 0x00000000, CX | CY << 16, Internet Explorer_Server1, ahk_id %WinID%
If ProtectInput = 1
BlockInput, Off
}
PostString(String, WinId, State = "Both")
{
Global ProtectInput
Global LetterDelayMin
Global LetterDelayMax
LI := StrLen(String)
Loop, %LI%
{
StringLeft, Char, String, 1
StringTrimLeft, String, String, 1
StringUpper, Char, Char
HexChar := "0x" Hex(Char)
If ProtectInput = 1
BlockInput, On
PostMessage, 0x100, %HexChar%,, Internet Explorer_Server1, ahk_id %WinID%
If State = Both
PostMessage, 0x101, %HexChar%,, Internet Explorer_Server1, ahk_id %WinID%
If ProtectInput = 1
BlockInput, Off
Random, LetterDelay, %LetterDelayMin%, %LetterDelayMax%
Sleep, %LetterDelay%
}
}
I just recently added something to close the gui, release the pwb/pdoc, and terminate COM at a given interval in hopes to fix the memory issues. Here's what I added (that doesn't help):
Code:
COM_CoUninitialize()
COM_Release(pwb)
VarSetCapacity(pwb, 0)
COM_AtlAxWinTerm()
WinGetPos, GuiX, GuiY, GuiW, GuiH, ahk_id %WinId%
Gui, Destroy
COM_AtlAxWinInit()
Gui, +LastFound
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),0,0,1024,768, "Shell.Explorer") )
If GuiState != Minimized
Gui, Show, x%guix% y%guiy% w1024 h768,, NA
Else
Gui, Show, w1024 h768,, Minimize
I think if the problem was related to COM, reloading the control would fix it. This does not seem to help at all. Hopefully I'm doing something simple wrong, or leaving something out. I've read through the tutorial post several times now and tried some various things with it, but I can't seem to find any related material. Anyone have some insight on the situation? The only thing I can think to do is "Reload" the script.