Our members are dedicated to PASSION and PURPOSE without drama!

VB.net - Leaking memory in webbrowser

Started by Stepkevh, November 26, 2012, 10:46:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Stepkevh

I'm using the axWebbrowser component because the normal webbrowser component isn't capable of
getting the newwindow event properly.

Looked at other fora and there they spoke of creating an extented webbrowser event  ???

Because i did'nt manage to do that i took the axWb component and worked with that.

The weirdest point comes now,
if i run the bot on my computer it can run for about 1500 spins and suddenly stops,
if a buddy of me runs it he can't get further then 530 spins.

On my computer the memory starts at 80000 kB and ends around 120000 kB.
On my buddys computer it starts at 85000 kB and stays stable with a max of 95000 kB.

I've read on other fora that the WB component dairs to leak memory because of the flash it plays inside it.
In this case that's the casino table...
But why isn't my buddys memory skyrocketing and mine is ??
And that also does'nt explain the different hangs on 1500 and 530 spins...

What i can say is that i ran the bot with DebugDiag and in the dump is written that Flash.ocx is causing leaks.

Is there a way to get that memory back, or other solutions to that webbrowser problem ?

Stephan



Skype :    stepke_vh@hotmail.com

Stepkevh

Updated the videocard driver last evening.

Changed some coding, especially the getpixel code.
I don't use the getpixel api anymore, i used the inbuild getpixel function now.

Rebuilded the bot and ran it.
Send it to my buddy and he ran it also.

Now we both get the same error.

The bot runs for 1250 spins and then halts with an error on "ntdll.dll"

Any ideas ?
Skype :    stepke_vh@hotmail.com

Ralph

"ntdll.dll" is very often in problem.  It is not easy to know which of the many problems it may be. The dll is from the older NT. Microsoft has some support pages handling some of the problems, which can be deadlock, malware infections, registery mess and other. You can try to reinstall windows, and if it not helps, it is probably not any damage in your system. The problems looks some different on your friends computer.

If you find the problem is from the casino flash, it should probably give such a problems in the webbrowsers, they had to deal with the problem at Adobe.
have you got any support from Adobe?
A memory leak from flash is not a likley reason. 

Check if any missing in coding can cause the browser to  reload the casino without dispose the former. a "New" in the wrong place in the code can be what it takes.   If you read the screen (as you must do every spin) look so you dispose all Bitmaps you read after theire use, otherwise it can be a lot of memory used which grows after each spins, and the GC not release.

There can be other reasons as well, in fact hard to advice.






Stepkevh

Ralph,

I'm using the piece of code that you provided on the hobbycode thread.


Friend Function PixelValue(ByVal ex As Integer, ByVal ey As Integer)
Dim BMP As New Drawing.Bitmap(1, 1)
Dim GFX As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP)
GFX.CopyFromScreen(New Drawing.Point(ex, ey), New Drawing.Point(0, 0), BMP.Size)
Dim myColor = BMP.GetPixel(0, 0)
 
PixelValue = myColor.R & myColor.G & myColor.B 
GC.Collect()
End Function


You're saying i need to dispose the bitmap properly, then what do i need to add in the code ?

Just a simple

BMP.Dispose
GFX.Dispose


instead of GC.collect ?
Skype :    stepke_vh@hotmail.com

Ralph

Yes you shall dispose the BMP, but it do not seems to be so much memory for a few pixels, but always dispose and try again.
I will check if I may have done some change after I post it.

Ralph

If you find the screen reading cause problem with the memory, you can try an other way. It will however change the returnvalue for all of the numbers.



   Friend Function checksumman(ex, yj)
        Dim ms As New MemoryStream
        Dim bmpBytes() As Byte
       
        Dim BMP As New Drawing.Bitmap(1,1)
        Dim GFX As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP)
        GFX.CopyFromScreen(ex, yj, 0, 0, BMP.Size)


        BMP.Save(ms, ImageFormat.Bmp)
        bmpBytes = ms.GetBuffer()
        BMP.Dispose()
        ms.Close()
        checksumman = bmpBytes
    End Function

Stepkevh

allright,

changed the code with bmp.dispose where needed.
memory leaks less but isn't completely over yet.

is it possible that the "Function Pixelvalue(ByVal ex As Integer, ByVal ey As Integer)" itself leaks

because vb.net says that's "pixelvalue is an object"

so declaring it as "Function Pixelvalue(ByVal ex As Integer, ByVal ey As Integer) As Integer"

should'nt that be better because pixelvalue returns a value and isn't a sub ??

otherwise the code always keeps pixelvalue in memory because its an object.

just correct me if i'm wrong.

Meanwhile i took a screenshot of the hanging, you will see that when the app hangs there's always
something missing on the table, this time it is the spinbutton.
Sometimes i get a black box painted over the "cashier" item or a big black box painted over "Statistics & connection status" items.

Could it be that the form or so doesn't repaint properly ?
Skype :    stepke_vh@hotmail.com

Ophis

Quote from: Stepkevh on November 27, 2012, 11:36:33 AM
Meanwhile i took a screenshot of the hanging, you will see that when the app hangs there's always
something missing on the table, this time it is the spinbutton.
Sometimes i get a black box painted over the "cashier" item or a big black box painted over "Statistics & connection status" items.
Could it be that the form or so doesn't repaint properly ?

When application hangs... it stops everything inside... also flash loading/rendering.
Multi Systems Tracker
➨ *Link Removed*

Stepkevh

Okay,

changed the code again.

now in that way that the table loads in an external ie webbrowser (not loading in the form)

with good hopes i started the bot, looked at memory and stayed pretty stable

and guess what ... after around 1300 spins it stopped working again  ???

so there has to be something wrong in my code but its weird that it stops after 1300 times running the same code  >:(
Skype :    stepke_vh@hotmail.com

Ralph

It is still suspection of memory leak, as it runs well probably until the memory runs out.  My bot can run for long, but are a bit cpu demanded.

Stepkevh

Ralph,

its not a memory leak i think.

because the memory of the bot stays between 50000 and 60000 kB

and the explorer window with the casino table stays at 72000 kB.

Is it possible that the call stack exceeds a limit ?
Skype :    stepke_vh@hotmail.com

Stepkevh

Back again after a lot of trial and (t)error   :P


Stupid "me" found the problem.

Looked at my call stack and saw that i created a recursive loop.

Problem solved by making an itteration loop  :thumbsup:
Skype :    stepke_vh@hotmail.com

Ralph

Fine!  It is usally so you find it examinating the code, as it is very hard to guess whitout reading the code. 

Stepkevh

But still i have the problem that the internal webbrowser leaks system memory

not that much but it leaks
and if i close the table it doesn't give all the memory back (webbrowser memory + leaked memory)

so i solved it with loading the table in an external explorer window.
if i close that it doesn't affect my bot memory and the IE memory is directly released.
i think that's the only option
Skype :    stepke_vh@hotmail.com

Ralph

Maybe, but if the users can use any browser, you may have issues regarding that. I do not know if you just read the screen and click and Excel do all other work, any browser will do.
I use javascript in my bot, and it should be some extra work coding the script for all browsers. Still not impossible but scripts are sometimes not readable in the same matter in all browsers. Margins can differ and can affect coordinates.. As any Windows has IE, you can tell the users it works best in IE.