System.OutOfMemoryException

ocbeta

Newcomer
Joined
Oct 15, 2003
Location
Learning Curve
I get the following error:
A first chance exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll

Additional information: Out of memory.

On this line of code in the debuger:

Dim imgImage As Bitmap = Bitmap.FromFile(strPath)

Code:
        Try
            Dim imgImage As Bitmap = Bitmap.FromFile(strPath)
           ImageList1.Images.Add(imgImage)
            Dim pic As New PictureBox()
            imgImage = imgImage.GetThumbnailImage(50, _
                  50, Nothing, Nothing)
            pic.Image = imgImage
            pic.Dock = DockStyle.Top
            Panel2.Controls.Add(pic)
            GC.Collect()
            strPath = Nothing
        Catch err As System.Exception
            System.Windows.Forms.MessageBox.Show(err.Message)
        End Try

I have tried disposing the image object. imgImage.Dispose()

Then I just get an error on the Form1 Public Class definition.

Also I have tried setting the variable imgImage = Nothing etc.

I am very stumped at this point.

Thanks for the help.
 

ocbeta

Newcomer
Joined
Oct 15, 2003
Location
Learning Curve
See the thing is that the piece of code I had worked great with a file.searcher class I created. However, I needed to do invoke method so that the directory watcher code can be marshalled.

Here is how the invoke method is working

Code:
    ByVal e As System.IO.FileSystemEventArgs)
        Dim File As File
        strPath = e.FullPath
        Dim mi As New MethodInvoker(AddressOf Me.AddThumbnail)
        Me.BeginInvoke(mi)

Error Message:
A first chance exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll

Additional information: Out of memory.

The line that throws the exception is:

Dim imgImage As Bitmap = Bitmap.FromFile(strPath)


Thanks for the help. I have been having a lot of trouble with this. I think the issue is with the method invoker. I am not sure why.
 

Menge

Centurion
Joined
Jul 3, 2003
Location
Recife - PE - Brazil
hey! this happened on some "corrupt" jpeg files. some files that weren't completely downloaded, understand?

just add some error catching there to find out which filename you are on and check the file.

to fix this, i believe you could go and create a Bitmap file, load that file with GDI+ and draw it and create the texture from that Bitmap. i think that'd work.
 

ocbeta

Newcomer
Joined
Oct 15, 2003
Location
Learning Curve
See the thing is that I never had this trouble with these images until I started using the method invoker etc.

Thanks for the tip. I tried declaring some things as bmp etc, but that still did not work.

I think there is an error witht he marshalling. Just need some more direction.
 

1001how2

Newcomer
Joined
Apr 21, 2009
Location
USA
I am getting occasional out of memory errors from RadUpload. The server apparently has plenty of physical memory. The web site never uses more than 25% of available memory, until this error occurs. Max request size is limited to 16MB. The progress area appears when the upload is used, so I know the memory management is functioning.
I have not been able to reproduce this myself, but I have talked to a couple of the users, and they said they were uploading relatively small files - well under the limit.
I have included the stack trace for the error
Any ideas on what could be causing this?
Stack trace: at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)
at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)
at System.Text.StringBuilder.Append(String value)
at Telerik.WebControls.RadUploadUtils.TextBodyWriter.Write(Byte[] buffer, Int32 index, Int32 count)
at Telerik.WebControls.RadUploadUtils.RequestParser.WriteProcessedPart(Int32 start, Int32 end)
at Telerik.WebControls.RadUploadUtils.RequestParser.ProcessRequest(RequestStream request)
at Telerik.WebControls.RadUploadHttpModule.Context_BeginRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
 

snarfblam

Ultimate Contributor
Joined
Jun 10, 2003
Location
USA
Among the exceptions that can be thrown from the Image.FromFile() method, per MSDN:
OutOfMemoryException

The file does not have a valid image format.
-or-
GDI+ does not support the pixel format of the file.
 
Top Bottom