Jump to content

Where is the memory leak in my code ?


 Share

Recommended Posts

i have this code for IE that clicks all links, copy all text paste it in notepad save and back to the page then navigate to next page and redo it again

#include <IE.au3>
$oIE = _IEAttach("LDLP - Librairie Du Liban Publishers")
$i = 0
copySelected ()

Func copySelected ()
   $i = $i + 1
$oLinks = _IELinkGetCollection ($oIE)
Sleep(1000)
For $oLink In $oLinks
 If StringInStr($oLink.href, "www.ldlp-dictionary.com/dictionaries/word/")> 0 Then _IEAction($oLink, "click")
    Sleep(100)
Next
Sleep(2000)
Send("^a")
Sleep(1000)
Send("^c")
Sleep(1000)
WinActivate("[CLASS:Notepad]", "")
Sleep(500)
Send("^v")
Sleep(500)
Send("^s")
Sleep(100)
MouseClick($MOUSE_CLICK_LEFT, 201, 469, 2)
ClipPut("")
Sleep(3000)
If $i < 3 Then
      copySelected ()
EndIf

EndFunc

First time every thing is going ok and Iexplore.exe process memory usage is about 100k, but second time when the loop starts the memory usage doubles and keep going up with every time it repeats the function again (going 650k usage and up)

what is making this leak ?

Link to comment
Share on other sites

See Remarks in helpfile at _IECreate() probably related to your problem:

Quote

New security in Windows Vista causes a new browser window to be created when a browser is instructed to navigate to a URL in a different security zone. This occurs as well with the initial creation and navigation initiated with _IECreate. The new window is a new browser instance and the previous browser object variable no longer points to it. There are several workarounds: 1) add #RequireAdmin to your code (this is required even if the account is part of the Administrator's Group and will propmt for credentials if necessary), 2) use _IEAttach to connect to the new browser window 3) add the target website to the Trusted Sites security zone in IE, 4) turn off "Protected Mode" in IE, or 5) disable UAC. Care must be taken to understand the implications of disabling IE security features when accessing untrusted sites.
 

 

Edited by Zedna
Link to comment
Share on other sites

well, it may be like chrome now. if it is opening new tabs each time, it will keep eating all your memory. I am thinking it MUST be 

_IELinkGetCollection ($oIE)

also you are calling your copy function recursively. you should just make a loop and have a break condition instead

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

I tested you code. how do you get the next link for the next page? it just loops forever getting the same data, also does not save file either. basically nothing works. 

also, in my test, my IE does not gobble up memory. you need to take a look at ProcessExplorer and see what is happening here.

so you know, your code does not work for me at all. I do not see where you are starting from to make this work either. in future, if you want serious help, give us detailed descriptions of what you need to do and all of your code. don't say it works when it does not. and give us examples that use websites that DON'T require a login to test!

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

this is out of the help file and can get list of all links.

; Open browser with basic example, get link collection,
; loop through items and display the associated link URL references

#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $oIE = _IECreate("www.autoitscript.com")
Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended

Local $sTxt = $iNumLinks & " links found" & @CRLF & @CRLF
For $oLink In $oLinks
    $sTxt &= $oLink.href & @CRLF
Next
MsgBox($MB_SYSTEMMODAL, "Link Info", $sTxt)

after that, create a loop that can go through that array of links, call a new function to click and extract that page, etc..

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...