Results 1 to 11 of 11

Thread: [RESOLVED] OutOfMemory problem?

  1. #1

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Resolved [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!

  2. #2

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Re: OutOfMemory problem?

    By the way, I have Windows 7 64bit with 4GB RAM and Intel Core i5.

  3. #3

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,117

    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

  5. #5

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Re: OutOfMemory problem?

    Quote Originally Posted by boops boops View Post
    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.

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,117

    Re: OutOfMemory problem?

    Quote Originally Posted by despotovski01 View Post
    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

  7. #7

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Re: OutOfMemory problem?

    Quote Originally Posted by boops boops View Post
    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.

  8. #8

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Re: OutOfMemory problem?

    Quote Originally Posted by boops boops View Post
    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!

  9. #9
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,117

    Re: OutOfMemory problem?

    Quote Originally Posted by despotovski01 View Post
    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

  10. #10

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    Re: OutOfMemory problem?

    Quote Originally Posted by boops boops View Post
    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.

  11. #11

    Thread Starter
    Lively Member despotovski01's Avatar
    Join Date
    Apr 2011
    Posts
    100

    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
  •  



Click Here to Expand Forum to Full Width