Out of memory error

E

Eric

Hi,

On my ASP.NET page I have a menu build out of linkbuttons, 2 images and some
text.

I can refresh the page over and over again via the refresh in the submenu
when I right click on the main page.

The Home link button does: response.redirect("~\default.aspx",true)

If I click on the home button of the page, every some time I get the
following error:

[OutOfMemoryException: Out of memory.]
System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement) +388176
System.Drawing.Image.FromFile(String filename) +6
DefaultClass.Page_Load(Object sender, EventArgs e) in
C:\Users\eervawo\Documents\Visual Studio
2008\Projects\FieldOperationsPortal\Default.aspx.vb:197
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


I only use the image.fromfile 2 times to access the image size, right after
that I put the variable on nothing.

What is causing this error to come up?
 
G

Guest

Hi,

On my ASP.NET page I have a menu build out of linkbuttons, 2 images and some
text.

I can refresh the page over and over again via the refresh in the submenu
when I right click on the main page.

The Home link button does: response.redirect("~\default.aspx",true)

If I click on the home button of the page, every some time I get the
following error:

[OutOfMemoryException: Out of memory.]
   System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement) +388176
   System.Drawing.Image.FromFile(String filename) +6
   DefaultClass.Page_Load(Object sender, EventArgs e) in
C:\Users\eervawo\Documents\Visual Studio
2008\Projects\FieldOperationsPortal\Default.aspx.vb:197
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

I only use the image.fromfile 2 times to access the image size, right after
that I put the variable on nothing.

What is causing this error to come up?

Hi Eric

Please check this thread at
http://www.velocityreviews.com/forums/t74291-systemoutofmemoryexception-out-of-memory.html

Hope this helps
 
E

Eric

Here is my code for that part:

'set pictures randomly
Dim path As String = Server.MapPath("./photos/")
Dim files As String() = Directory.GetFiles(path)
Dim myPlaatjeLinksMiddenStyle As New WebControls.Style
Dim myPlaatjeRechtsMiddenStyle As New WebControls.Style
Dim r As New Random
Dim fi As FileInfo
Dim num1, num2 As Integer
Dim hs As RectangleHotSpot

myPlaatjeLinksMiddenStyle = New WebControls.Style
myPlaatjeLinksMiddenStyle.CssClass = "DefaultPlaatjeLinksMidden"
myPlaatjeRechtsMiddenStyle = New WebControls.Style
myPlaatjeRechtsMiddenStyle.CssClass = "DefaultPlaatjeRechtsMidden"

num1 = r.Next(0, files.Length)
fi = New FileInfo(files(num1))

Dim im As Drawing.Image
Dim imW, imH As Integer
im = Drawing.Image.FromFile(Server.MapPath("./photos/") + fi.Name)

imH = 152
imW = (imH / im.Height) * im.Width
If imW > 211 Then
imW = 211
imH = (imW / im.Width) * im.Height
End If
im = Nothing

If 211 - imW > 20 Then
Me.imVoorwoordLinks.ApplyStyle(myPlaatjeLinksMiddenStyle)
End If

hs = New RectangleHotSpot
hs.HotSpotMode = HotSpotMode.Navigate
hs.NavigateUrl = "~/photos/" + fi.Name
hs.Bottom = imH
hs.Top = 0
hs.Left = 0
hs.Right = imW
Me.imVoorwoordLinks.HotSpots.Add(hs)

Me.imVoorwoordLinks.Width = imW
Me.imVoorwoordLinks.Height = imH
Me.imVoorwoordLinks.ImageUrl = "~/photos/" + fi.Name
fi = Nothing

Dim aantalkeer As Integer = 50
num2 = num1
Do While num1 = num2 And aantalkeer > 0
num2 = r.Next(0, files.Length)
aantalkeer -= 1
Loop
fi = New FileInfo(files(num2))
im = Drawing.Image.FromFile(Server.MapPath("./photos/") + fi.Name)

imH = 152
imW = (imH / im.Height) * im.Width
If imW > 211 Then
imW = 211
imH = (imW / im.Width) * im.Height
End If
im = Nothing

If 211 - imW > 20 Then
Me.imVoorwoordRechts.ApplyStyle(myPlaatjeRechtsMiddenStyle)
End If

hs = New RectangleHotSpot
hs.HotSpotMode = HotSpotMode.Navigate
hs.NavigateUrl = "~/photos/" + fi.Name
hs.Bottom = imH
hs.Top = 0
hs.Left = 0
hs.Right = imW
Me.imVoorwoordRechts.HotSpots.Add(hs)

Me.imVoorwoordRechts.Width = imW
Me.imVoorwoordRechts.Height = imH
Me.imVoorwoordRechts.ImageUrl = "~/photos/" + fi.Name
fi = Nothing

I don't see anything wrong with it, but I may be missing something..

rg,
Eric


Anon User said:
Hi,

On my ASP.NET page I have a menu build out of linkbuttons, 2 images and some
text.

I can refresh the page over and over again via the refresh in the submenu
when I right click on the main page.

The Home link button does: response.redirect("~\default.aspx",true)

If I click on the home button of the page, every some time I get the
following error:

[OutOfMemoryException: Out of memory.]
System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement) +388176
System.Drawing.Image.FromFile(String filename) +6
DefaultClass.Page_Load(Object sender, EventArgs e) in
C:\Users\eervawo\Documents\Visual Studio
2008\Projects\FieldOperationsPortal\Default.aspx.vb:197
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

I only use the image.fromfile 2 times to access the image size, right after
that I put the variable on nothing.

What is causing this error to come up?

Hi Eric

Please check this thread at
http://www.velocityreviews.com/forums/t74291-systemoutofmemoryexception-out-of-memory.html

Hope this helps
 
E

Eric

I have put ine im.dispose in just before im = nothing, but I still get the
error.

Could it be something on the server or is it really in my code?


Patrice said:
You need to explicitely call im.Dispose to clean up unmanaged resources.
Unlike non garbage collected environment setting the variable to nothing
does nothing more behind the scene than settings this variable to Nothing...

Youi may want to check also the Using statement that allows to create a
block that will dispose the variable when the block ends...

--
Patrice


Eric said:
Here is my code for that part:

'set pictures randomly
Dim path As String = Server.MapPath("./photos/")
Dim files As String() = Directory.GetFiles(path)
Dim myPlaatjeLinksMiddenStyle As New WebControls.Style
Dim myPlaatjeRechtsMiddenStyle As New WebControls.Style
Dim r As New Random
Dim fi As FileInfo
Dim num1, num2 As Integer
Dim hs As RectangleHotSpot

myPlaatjeLinksMiddenStyle = New WebControls.Style
myPlaatjeLinksMiddenStyle.CssClass = "DefaultPlaatjeLinksMidden"
myPlaatjeRechtsMiddenStyle = New WebControls.Style
myPlaatjeRechtsMiddenStyle.CssClass = "DefaultPlaatjeRechtsMidden"

num1 = r.Next(0, files.Length)
fi = New FileInfo(files(num1))

Dim im As Drawing.Image
Dim imW, imH As Integer
im = Drawing.Image.FromFile(Server.MapPath("./photos/") + fi.Name)

imH = 152
imW = (imH / im.Height) * im.Width
If imW > 211 Then
imW = 211
imH = (imW / im.Width) * im.Height
End If
im = Nothing

If 211 - imW > 20 Then
Me.imVoorwoordLinks.ApplyStyle(myPlaatjeLinksMiddenStyle)
End If

hs = New RectangleHotSpot
hs.HotSpotMode = HotSpotMode.Navigate
hs.NavigateUrl = "~/photos/" + fi.Name
hs.Bottom = imH
hs.Top = 0
hs.Left = 0
hs.Right = imW
Me.imVoorwoordLinks.HotSpots.Add(hs)

Me.imVoorwoordLinks.Width = imW
Me.imVoorwoordLinks.Height = imH
Me.imVoorwoordLinks.ImageUrl = "~/photos/" + fi.Name
fi = Nothing

Dim aantalkeer As Integer = 50
num2 = num1
Do While num1 = num2 And aantalkeer > 0
num2 = r.Next(0, files.Length)
aantalkeer -= 1
Loop
fi = New FileInfo(files(num2))
im = Drawing.Image.FromFile(Server.MapPath("./photos/") + fi.Name)

imH = 152
imW = (imH / im.Height) * im.Width
If imW > 211 Then
imW = 211
imH = (imW / im.Width) * im.Height
End If
im = Nothing

If 211 - imW > 20 Then
Me.imVoorwoordRechts.ApplyStyle(myPlaatjeRechtsMiddenStyle)
End If

hs = New RectangleHotSpot
hs.HotSpotMode = HotSpotMode.Navigate
hs.NavigateUrl = "~/photos/" + fi.Name
hs.Bottom = imH
hs.Top = 0
hs.Left = 0
hs.Right = imW
Me.imVoorwoordRechts.HotSpots.Add(hs)

Me.imVoorwoordRechts.Width = imW
Me.imVoorwoordRechts.Height = imH
Me.imVoorwoordRechts.ImageUrl = "~/photos/" + fi.Name
fi = Nothing

I don't see anything wrong with it, but I may be missing something..

rg,
Eric


Anon User said:
Hi,

On my ASP.NET page I have a menu build out of linkbuttons, 2 images and
some
text.

I can refresh the page over and over again via the refresh in the
submenu
when I right click on the main page.

The Home link button does: response.redirect("~\default.aspx",true)

If I click on the home button of the page, every some time I get the
following error:

[OutOfMemoryException: Out of memory.]
System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement) +388176
System.Drawing.Image.FromFile(String filename) +6
DefaultClass.Page_Load(Object sender, EventArgs e) in
C:\Users\eervawo\Documents\Visual Studio
2008\Projects\FieldOperationsPortal\Default.aspx.vb:197
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1061

I only use the image.fromfile 2 times to access the image size, right
after
that I put the variable on nothing.

What is causing this error to come up?

Hi Eric

Please check this thread at
http://www.velocityreviews.com/forums/t74291-systemoutofmemoryexception-out-of-memory.html

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top