7 Replies - 13808 Views - Last Post: 10 September 2010 - 12:27 AM Rate Topic: -----

#1 Dumpen  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 21-March 08

Out of memory exception when loading image with bitmap

Posted 16 June 2009 - 01:05 PM

Hello all

I have a mysql table with some rows in it that contain a path to a jpg file.

Here is a example of the path:
images/portfolio/lille_ilveaWebshop.jpg

The file excists on the webhost so that is not a problem.

I am loading the jpg file into a bitmap in a foreach.

It works fine when I am on a local server, but when I upload it to my webhost it says:

Quote

Server Error in '/' Application.
Out of memory.

Exception Details: System.OutOfMemoryException: Out of memory.

[OutOfMemoryException: Out of memory.]
System.Drawing.Bitmap..ctor(String filename) +376480
Referencer.Page_Load(Object sender, EventArgs e) +561
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.onload(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


I cant seem to figure out just why it would do that.

Here is the code I am using:
			foreach (DataRow Row in objPortFac.VisReference(refKatID).Rows)
			{
				// Create a new bitmap with the path from the row
				// fldStortBillede is the field that contains the path
				Bitmap objStortBillede = new Bitmap(Server.MapPath(Row["fldStortBillede"].ToString()));

				// Dispose the bitmap after use
				objStortBillede.Dispose();
}


Any suggestions?

This post has been edited by Dumpen: 17 June 2009 - 12:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Out of memory exception when loading image with bitmap

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Out of memory exception when loading image with bitmap

Posted 16 June 2009 - 06:09 PM

Post the code for the entire method where you are loading the bitmap.
Was This Post Helpful? 0
  • +
  • -

#3 Dumpen  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 21-March 08

Re: Out of memory exception when loading image with bitmap

Posted 16 June 2009 - 10:44 PM

View PostJayman, on 16 Jun, 2009 - 05:09 PM, said:

Post the code for the entire method where you are loading the bitmap.


That is the entire code :)
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Out of memory exception when loading image with bitmap

Posted 17 June 2009 - 12:02 PM

Quote

I am loading the jpg file into a bitmap in a foreach.

That cannot be true based on what you stated in your first post, you said it was in a foreach loop.

So show all of your code.
Was This Post Helpful? 0
  • +
  • -

#5 Dumpen  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 21-March 08

Re: Out of memory exception when loading image with bitmap

Posted 17 June 2009 - 12:07 PM

Oh, yeah sorry

I edited my first post
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Out of memory exception when loading image with bitmap

Posted 17 June 2009 - 12:30 PM

How many times is the foreach loop iterating?

Each time it iterates it will instantiate a new Bitmap.

How much memory is on the server?

How big are the JPG files?

Each of those questions can have an impact on why you are running out of memory.
Was This Post Helpful? 0
  • +
  • -

#7 Dumpen  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 21-March 08

Re: Out of memory exception when loading image with bitmap

Posted 17 June 2009 - 12:59 PM

View PostJayman, on 17 Jun, 2009 - 11:30 AM, said:

How many times is the foreach loop iterating?

Each time it iterates it will instantiate a new Bitmap.

How much memory is on the server?

How big are the JPG files?

Each of those questions can have an impact on why you are running out of memory.


Well the foreach loop is iterating a diffrent amount of times. It can be 2 or 5 or 6 or x

I dont know (How do I figure that out?)

The size is also diffrent from time to time but between 200kb and 800kb (roughly)

I figured out it can handle 2 or 3 images but then the error occur

Seems to be a bad soloution

This post has been edited by Dumpen: 17 June 2009 - 01:00 PM

Was This Post Helpful? 0
  • +
  • -

#8 Guest_keesje*


Reputation:

Re: Out of memory exception when loading image with bitmap

Posted 10 September 2010 - 12:27 AM

Sometimes the bitmap constructor will give outofmemory exceptions on corrupted image files
Check the files that give the exception, if you can't open them in an application, chances are that there's a corrupt image.

View PostDumpen, on 17 June 2009 - 11:59 AM, said:

View PostJayman, on 17 Jun, 2009 - 11:30 AM, said:

How many times is the foreach loop iterating?

Each time it iterates it will instantiate a new Bitmap.

How much memory is on the server?

How big are the JPG files?

Each of those questions can have an impact on why you are running out of memory.


Well the foreach loop is iterating a diffrent amount of times. It can be 2 or 5 or 6 or x

I dont know (How do I figure that out?)

The size is also diffrent from time to time but between 200kb and 800kb (roughly)

I figured out it can handle 2 or 3 images but then the error occur

Seems to be a bad soloution

Was This Post Helpful? 0

Page 1 of 1