memory leak

Grega

Active member
Joined
Jun 21, 2007
Messages
25
Programming Experience
1-3
Hi all,
I am making a VB .NET application,
there is a picturebox on the form in which i want to chnge images of a logo so it animates.
this is hapening in a separate thread adressof ChangeLogo..I update picturebox on a form trough a delegate.
Does anyone know what I am doing wrong that this thread is causing a memory leak?
Thanks.
Best regards,
Grega
VB.NET:
Private Sub ChangeLogo()
        Dim logo As Image
        Dim logonumber1 As New System.Text.StringBuilder
        Do
            logonumber1.Remove(0, logonumber1.Length)
            logonumber1.Append("Logo")
            logonumber1.Append(k.ToString.PadLeft(2, "0"))
            logo = CType(My.Resources.Resources.ResourceManager.GetObject(logonumber1.ToString), System.Drawing.Bitmap)
            PictureBoxVisible(Me.PictureBox2, logo)
            Thread.Sleep(50)
            k += 1
            k = k Mod 20
        Loop
    End Sub

 Dim PictureBoxVisible1 As PictureBoxVisibleDelegate

    Private Sub PictureBoxVisible(ByVal ctr As Control, ByVal img As Image)
        If ctr.InvokeRequired Then
            PictureBoxVisible1 = New PictureBoxVisibleDelegate(AddressOf PictureBoxVisible)
            Invoke(PictureBoxVisible1, ctr, img)
        Else
            Dim pbx As PictureBox
            If TypeOf (ctr) Is PictureBox Then
                pbx = ctr
                pbx.Image = img
            End If


            ctr.Visible = True
        End If
    End Sub
 
Last edited by a moderator:
Can you explain a little
Sure, :)

The thing is when I run the application, (it runs on Windows CE 5.0)
it starts consuming RAM until it runs out and it throws an memory unhandled exception, I am quite certain this part of code is the problem becose if I remove it the memory stays the same.

The code switches images that are in resources (approx. 20 images) and shows them in a picturebox...between each switch there is a short delay, so the whole thing looks like a gif animation(which are not supported in CF)

Now I think the problem is either in the part where invoke the delegate, or the cast to the image from resources?

Thanks
Grega
 
I believe Memory Leak is not in .NET.

Now I think the problem is either in the part where invoke the delegate, or the cast to the image from resources?

I think the problem is in the below mentioned code. Your are creating objects again and again in the loop.
VB.NET:
           logo = CType(My.Resources.Resources.ResourceManager.GetObject(logonumber1.ToString), System.Drawing.Bitmap)
 
I believe Memory Leak is not in .NET.



I think the problem is in the below mentioned code. Your are creating objects again and again in the loop.
VB.NET:
           logo = CType(My.Resources.Resources.ResourceManager.GetObject(logonumber1.ToString), System.Drawing.Bitmap)

Yep thats what I thought, but how else can I cycle trough the resources and assign the current image to picturebox?

Thanks for your help,

regards Grega
 
Back
Top