Picture Box not releasing memory

dejota6
06-08-2004, 03:33 PM
I've got a small application that is supposed to simply be a slide show program. I have folder of .jpg's that are going to be displayed. Simple...

The problem I'm having is that the Picture Box, when it changes pictures, is not releasing the memory completely. and after only a few loops through all the pictures, there is a significant rise in memory usage.

the way i'm doing it (in a nutshell), is i have a picture box and a timer. on the timer event (every 5 seconds), i change the picBox1.Image property.

Is there something else I need to do, to cause the memory to remain "constant" over the life of the application. The reason for the concern, is this program will be running for very long periods of time. Possibly weeks at a time, and if the memory would continue to rise...well, that's not good.

Any help would be great, If i need to post code, or anything, please let me know.....

wildfire1982
06-09-2004, 01:43 AM
You might want to try setting the image to nothing when you change the pictures so that the program assumes the picture is finished with. Could we see the code for your picture change?

dejota6
06-09-2004, 08:11 AM
Private Sub tmrPic_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPic.Tick
FillPic()
End Sub
Private Sub FillPic()
picBox1.Image = Nothing
picBox1.Image = Image.FromFile("J:/holiday/" & PicCount & ".jpg")
PicCount = PicCount + 1
If PicCount > 4 Then PicCount = 1
End Sub


PicCount is a counter, the images i'm working with are number 1.jpg through 4.jpg...simply for testing purposes....

as you can tell, there is a pictureBox named picBox1 and a timer called tmrPic with an interval of 5000 milliseconds (5 seconds)

dejota6
06-09-2004, 09:15 AM
As you can see, i already tried the setting it to Nothing, but the memory is still not released properly.

Negative0
06-09-2004, 01:12 PM
My guess as to what is happening is that the .NET framework is not releasing the memory from the image. It will eventually release the memory when the garbage collector runs. If you want to force the .NET to run the garbage collector, you can call Gc.Collect after you set the image to nothing and I think all of you memory usage problems should be fine.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum