-
Jun 18th, 2011, 06:31 AM
#1
Thread Starter
Lively Member
[RESOLVED] OutOfMemory problem?
Hi all! I'm working on a program. It's some sort of a slideshow program. It works fine until one moment, when an OutOfMemory exception appears. Here's the code:
Code:
Private Sub TimerCase2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TimerCase2.Tick
Dim loop2_1 As Integer = CType(txtLoop2_1.Text, Integer)
Dim loop2_2 As Integer = CType(txtLoop2_2.Text, Integer)
intNumberOfLoops += 1
If intNumberOfLoops > loop2_1 Then
If Not intNumberOfLoops = 0 Then
intNumberOfLoops += 1
End If
If intNumberOfLoops > loop2_2 Then
Previewer.PictureBox1.Image = Nothing
End If
CurrentImage = CurrentImage + 1
If CurrentImage > Case2Images2.Count Then
CurrentImage = 0
End If
Previewer.PictureBox1.Image = Image.FromFile(Case2Images2.Item(CurrentImage))
End If
CurrentImage = (CurrentImage + 1)
If CurrentImage > Case2Images1.Count Then
CurrentImage = 0
End If
Previewer.PictureBox1.Image = Image.FromFile(Case2Images1.Item(CurrentImage))
End Sub
Please help me fix the problem. I'm not familiar with this kind of exceptions.
Thanks in advance!
-
Jun 18th, 2011, 07:48 AM
#2
Thread Starter
Lively Member
Re: OutOfMemory problem?
By the way, I have Windows 7 64bit with 4GB RAM and Intel Core i5.
-
Jun 18th, 2011, 11:29 AM
#3
Thread Starter
Lively Member
-
Jun 18th, 2011, 11:41 AM
#4
Re: OutOfMemory problem?
I don't know why you get an OutOfMemory exception. Often when that happens, it isn't because you have an actual shortage of memory. Some parts of the Framework seem to use it simply as a default exception.
All the same, I'm surprised you aren't getting IndexOutOfRange exceptions whenever CurrentImage reaches Case2Images.Count, because Count is 1 more than the maximum index. You need to correct that in two places; maybe it will also correct the OOM error. BB
-
Jun 18th, 2011, 11:55 AM
#5
Thread Starter
Lively Member
Re: OutOfMemory problem?
Originally Posted by boops boops
I don't know why you get an OutOfMemory exception. Often when that happens, it isn't because you have an actual shortage of memory. Some parts of the Framework seem to use it simply as a default exception.
All the same, I'm surprised you aren't getting IndexOutOfRange exceptions whenever CurrentImage reaches Case2Images.Count, because Count is 1 more than the maximum index. You need to correct that in two places; maybe it will also correct the OOM error. BB
Does this 'OutOfMemory' exception has anything with the number of 'Public' variables? Because I have many of them and I've read something about that on the Internet, but I'm not sure.
-
Jun 18th, 2011, 12:53 PM
#6
Re: OutOfMemory problem?
Originally Posted by despotovski01
Does this 'OutOfMemory' exception has anything with the number of 'Public' variables? Because I have many of them and I've read something about that on the Internet, but I'm not sure.
I've never heard of that and it seems unlikely to me. Assuming you've fixed the indexing error, there might be something wrong with one of the images -- maybe too large, or an invalid format. It's often not until you try to show it in the PictureBox that the problem shows up, and it can throw an OOM. What happens if you try with a different bunch of images?
BB
-
Jun 18th, 2011, 01:03 PM
#7
Thread Starter
Lively Member
Re: OutOfMemory problem?
Originally Posted by boops boops
I've never heard of that and it seems unlikely to me. Assuming you've fixed the indexing error, there might be something wrong with one of the images -- maybe too large, or an invalid format. It's often not until you try to show it in the PictureBox that the problem shows up, and it can throw an OOM. What happens if you try with a different bunch of images?
BB
I think I've found the problem. The code that I've posted before is a mess. That may be the problem.
-
Jun 19th, 2011, 01:48 PM
#8
Thread Starter
Lively Member
Re: OutOfMemory problem?
Originally Posted by boops boops
I've never heard of that and it seems unlikely to me. Assuming you've fixed the indexing error, there might be something wrong with one of the images -- maybe too large, or an invalid format. It's often not until you try to show it in the PictureBox that the problem shows up, and it can throw an OOM. What happens if you try with a different bunch of images?
BB
My problems are getting fixed. Thanks for your help!
-
Jun 19th, 2011, 05:29 PM
#9
Re: OutOfMemory problem?
Originally Posted by despotovski01
My problems are getting fixed. Thanks for your help!
Great. Please let us know if you can figure out what the problem was, and if it's clear please mark this thread resolved. BB
-
Jun 20th, 2011, 02:10 AM
#10
Thread Starter
Lively Member
Re: OutOfMemory problem?
Originally Posted by boops boops
Great. Please let us know if you can figure out what the problem was, and if it's clear please mark this thread resolved. BB
The problem is with my code. It was all messed up. Now I'm cleaning it and I will mark the thread resolved when I finish my program.
-
Jun 20th, 2011, 08:31 AM
#11
Thread Starter
Lively Member
Re: OutOfMemory problem?
Ok, I've made the program. The thread is resolved.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|