MTSkull Posted February 12, 2004 Posted February 12, 2004 The following code causes an Out Of Memory Error when it cycles continuously as a screen saver, any thoughts. Public bFirstMove As Boolean = True Public Pics() As String Public pos As Int16 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles MyBase.Load Me.CenterToScreen() picBox.Height = Me.Height picBox.Width = Me.Width Pics = Directory.GetFiles("C:\Pictures") pos = 0 picBox.Image = Drawing.Bitmap.FromFile(Pics(pos)) Me.Cursor.Hide() End Sub Private Sub Form1_KeyUp(ByVal sender As Object, _ ByVal e As System.Windows.Forms.KeyEventArgs) _ Handles MyBase.KeyUp Me.Close() End Sub Private Sub picBox_MouseMove(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles picBox.MouseMove Static iCount As Long If iCount > 2 Then Me.Close() Else iCount = iCount + 1 End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Timer1.Tick pos += 1 If pos = UBound(Pics) Then pos = 0 End If picBox.Image = Drawing.Bitmap.FromFile(Pics(pos)) End Sub Quote "Beer is proof that God loves us and wants us to be happy." -Benjamin Franklin
*Experts* Bucky Posted February 12, 2004 *Experts* Posted February 12, 2004 How quickly is the timer's interval set for? And after how long does the error occur? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
samsmithnz Posted February 12, 2004 Posted February 12, 2004 why are you using the Timer1_Tick event? shouldn't you be using a form repaint? Quote Thanks Sam http://www.samsmith.co.nz
MTSkull Posted February 12, 2004 Author Posted February 12, 2004 Bucky, The timer tick event is set to 5000 (5 seconds), error occures after an hour or so. samsmithnz, Well the short awnser (and not meaning to be a smart ***) is that was how I wrote it, however, I am open to suggestions if you know a better way. As it is stands, it runs for about an hour before it crashes. I set the form to normal (it is usually set to Maximize) and then ran it and opened the task manager to watch what happened to the memory. I had thought it was overloading when it rolled over, but the memory steadly increased as each new picture was displayed. So I am currently running a test where I placed this code in the timer tick event picBox.Image.Dispose picBox.Image = Drawing.Bitmap.FromFile(Pics(pos)) On my quick test this seemed to work but I am running an extended test now (1:30). If that works I will leave it on overnight. Thanks Brian Quote "Beer is proof that God loves us and wants us to be happy." -Benjamin Franklin
candyman Posted March 14, 2004 Posted March 14, 2004 I have a similar Problem with a closed source app. I�ve made an app that monitors the memory usage and have been using Microsoft�s empty.exe to Shove Memory to the Page file after it rises above 75 Megs, but after a few Runs I will have a HUGE Page file (i.e. Over 300 Megs in Ten Minuets). Any Clues how to stop this? (and no I can�t upgrade) Quote
DR00ME Posted March 14, 2004 Posted March 14, 2004 I have had similar problems with some image handling things until I found a solution which were .Dispose ..... my program crashed faster tough ... anyway try to look for some flying objects which are eating up memory... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
*Experts* Nerseus Posted March 15, 2004 *Experts* Posted March 15, 2004 There's a known issue with a Picture box loading pictures directly from disk - basically it holds onto that image. You can test this by loading a picture from disk into a picturebox using the load method then trying to overwrite that image on disk (you can't). I think the workaround was to load the picture into an Image, then load the Image object into a Bitmap and assign that bitmap to the picturebox's image property. Then you can dispose of the Image and the PictureBox will cleanup after itself. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
TechnoTone Posted March 15, 2004 Posted March 15, 2004 But it's not the PictureBox doing the load - it is a shared method of the Bitmap class. Maybe the problem is with using the Bitmap class to do the load and the workaround is to use the Image class? Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.