AutoHotkey Community

It is currently May 27th, 2012, 1:39 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: June 13th, 2009, 12:00 am 
Offline

Joined: December 30th, 2007, 5:42 pm
Posts: 31
Location: East Coast
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Updates
PostPosted: June 13th, 2009, 6:39 pm 
Offline

Joined: December 30th, 2007, 5:42 pm
Posts: 31
Location: East Coast
The memory issues appear when you play the games in the browser as well. I tried playing a few games in the IE browser manually and the iexplorer process just keeps eating more and more memory. I guess this is some sort of memory issue within the flash code, or some compatibility issue with flash 10 / IE8. From what I've read, it is possible to have memory leaks with postmessage though. If I'm mistaken, or anyone has any additional info, please let me know.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2009, 12:16 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
It is a sad fact that many current web designers think it is un necesary to clean up memory within apps and yes even google earth will chew it up and spit it out so its not surprising that a flash app does this as well

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks
PostPosted: June 14th, 2009, 8:26 am 
Offline

Joined: December 30th, 2007, 5:42 pm
Posts: 31
Location: East Coast
Yeah, the leak being caused by the flash was something I anticipated, but was last to expect. Considering the level of difficulty with a language like flash, I would expect a higher level of professionalism. Believe it or not, this particular app is used by millions of people and is currently very popular. I will not mention the specific site/app, so as to not draw any unwanted attention to it. Back on point, thanks a lot for your tutorials Tank and for your response. Your effort is much appreciated on my end.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group