Home All Groups Group Topic Archive Search About

Intermittent 'Out of memory' error

Author
18 Jul 2006 12:17 AM
Liverpool fan
I have a VB .NET windows application that is throwing an intermittent
'out of memory' error. Here is the call stack.

Out of memory.

   at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
   at System.Windows.Forms.DibGraphicsBufferManager.CreateBuffer(IntPtr
src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
   at
System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(Graphics
targetGraphics, IntPtr targetDC, Rectangle targetBounds)
   at System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(IntPtr
target, Rectangle targetBounds)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam) Source = System.Drawing



The program uses our own timer form that gives a countdown between each
processing cycle. Each processing cycle looks for reports that need
running from 3 SQL Server 2000 databases (don't ask why there are
three). Also, once a day it does a bcp load of data into each of the 3
database and runs various snapshot tasks.

I don't think the details are important besides to say it is doing a
fair amount of processing.

The question is, is this likely to be caused by memory leakage. Sounds
like it to me but I thought that I'd find out if anybody else gets this
error. The call stack is always the same but it fails at various times
of day but sometimes not for 2 weeks.

I have been monitoring the memory usage and it does go up gradually
over time from 120Mb to 150Mb. I have added garbage collection calls to
no effect.

The program uses COM in various places.

Any advice greatly appreciated.

Author
18 Jul 2006 4:43 AM
Cor Ligthert [MVP]
Liverpool fan,

Have a look about all that is written about dispose on MSDN to clean up your
not managed resources.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconimplementingdisposemethod.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconFinalizeDispose.asp

Using the dispose methods implemented in the managed classes will probably
not help you as well as calling the gc for the same,

I hope this helps,

Cor


Show quoteHide quote
"Liverpool fan" <chris.no***@feltex.com> schreef in bericht
news:1153181841.502412.19290@m73g2000cwd.googlegroups.com...
>I have a VB .NET windows application that is throwing an intermittent
> 'out of memory' error. Here is the call stack.
>
> Out of memory.
>
>   at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
>   at System.Windows.Forms.DibGraphicsBufferManager.CreateBuffer(IntPtr
> src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
>   at
> System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(Graphics
> targetGraphics, IntPtr targetDC, Rectangle targetBounds)
>   at System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(IntPtr
> target, Rectangle targetBounds)
>   at System.Windows.Forms.Control.WmPaint(Message& m)
>   at System.Windows.Forms.Control.WndProc(Message& m)
>   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
>   at System.Windows.Forms.Button.WndProc(Message& m)
>   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
>   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
>   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
> msg, IntPtr wparam, IntPtr lparam) Source = System.Drawing
>
>
>
> The program uses our own timer form that gives a countdown between each
> processing cycle. Each processing cycle looks for reports that need
> running from 3 SQL Server 2000 databases (don't ask why there are
> three). Also, once a day it does a bcp load of data into each of the 3
> database and runs various snapshot tasks.
>
> I don't think the details are important besides to say it is doing a
> fair amount of processing.
>
> The question is, is this likely to be caused by memory leakage. Sounds
> like it to me but I thought that I'd find out if anybody else gets this
> error. The call stack is always the same but it fails at various times
> of day but sometimes not for 2 weeks.
>
> I have been monitoring the memory usage and it does go up gradually
> over time from 120Mb to 150Mb. I have added garbage collection calls to
> no effect.
>
> The program uses COM in various places.
>
> Any advice greatly appreciated.
>
Author
18 Jul 2006 5:08 AM
Liverpool fan
Thanks for replying Cor. I has already tried enforcing a Garbage
Collection which seemed to help to an extent but only to decrease the
frequency of the error. I'll have a look at the articles and compare to
what I am doing already as far as COM is concerned.

Here is the Timer calling routine. I have changed it slightly in that
instead of creating a new timer dialog for each loop, I reuse the
previous one. This seems to have helped immensely but I now have a 4K
creeping of memory usage for each loop (when nothing is executed).

Private Sub StartTimer()

        Dim dtloadfull, dtjobscan As Date
        Dim sLoadFull As String = "Load Sales Extract"
        Dim sprocessjobs As String = "Process Job Queue"

        Me.ListBox1.Items.Add("Started " & Date.Now.ToString)
        Me.ListBox1.SelectedIndex = Me.ListBox1.Items.Count - 1

        ' next order scan
        dtjobscan = DateAdd(DateInterval.Minute, myJobScanInterval,
Now)

        ' launch the timer
        f = New dlgZTimer
        f.TimerIntervalSecs = 1

        Do
            'Clean up memory
            GC.Collect

            ' get time of next full update. may be next day.
            If myFullLoadTime = "" Then
                dtloadfull = Nothing
            Else
                dtloadfull =
System.Convert.ToDateTime(Now.ToShortDateString & " " & myFullLoadTime)
                Do While dtloadfull < Now
                    dtloadfull = DateAdd(DateInterval.Day, 1,
dtloadfull)
                Loop
                Me.lblProgress.Text = "Progress   (" & "Next full
extract load at " & dtloadfull.ToString & ")"
                Application.DoEvents()
            End If

            ' next order scan
            dtjobscan = DateAdd(DateInterval.Minute, myJobScanInterval,
Now)

            f.TimerTitle = ""

            If myFullLoadTime = "" Then
                f.TimerTitle = sprocessjobs
                f.TargetTime = dtjobscan
            Else
                ' if full load is in the next 10 minutes, wait for it
                If dtloadfull <= DateAdd(DateInterval.Minute, 10, Now)
Then
                    f.TimerTitle = sLoadFull
                    f.TargetTime = dtloadfull
                Else
                    ' no trans available, check for orders
                    f.TimerTitle = sprocessjobs
                    f.TargetTime = dtjobscan
                End If
            End If

            If f.TimerTitle <> "" Then

                If f.ShowDialog(Me) = DialogResult.OK Then
                    If f.TimerTitle = sprocessjobs Then

                        If myMultiThreaded = True Then
                            ProcessJobQueueMultiThreaded()
                        Else
                            ProcessJobQueue()
                        End If


                        ' test for network connection
                        If myLastNetworkCheck < Now.AddHours(-1) Then
                            Try
                                DisplayHistory("******** Testing
network connection")
                                Dim str As String()
                                str =
System.IO.Directory.GetFiles(myBCP_Full_Directory)
                                myLastNetworkCheck = Now
                            Catch ex As Exception
                                DisplayErrorInList(ex)
                            End Try
                        End If

                    End If

                    If f.TimerTitle = sLoadFull Then
                        ProcessEOD()

                        ' test to see if EOD data has been loaded
                        CheckEODStatus()
                    End If
                Else
                    ' Cancelled
                    f.Dispose()
                    f = Nothing
                    Exit Sub
                End If
            End If
        Loop

    End Sub

I have focussed on this because of the rate that the memory was being
used up even when the program wasn't doing anything but running the
timer. Seemed to be a prime candidate.

Any thoughts greatly appreciated.