|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB.NET Service + Out of MemoryI have a vb.net service which copies images and resizes images from a local
directory to a remote one. When I drop images into the local directory I get an out of memory error after several images - the exception is on the following line. Dim img As Image = Image.FromFile(path) The machine has a GB of ram, and there is not a great deal running. Each image is about 2000 x 2000 PIXELS Thanks for any help in advance Rocky wrote:
> I have a vb.net service which copies images and resizes images from a local Hmm... My guess would be that you aren't calling Dispose on the image> directory to a remote one. > > When I drop images into the local directory I get an out of memory error > after several images - the exception is on the following line. > > Dim img As Image = Image.FromFile(path) > > The machine has a GB of ram, and there is not a great deal running. > Each image is about 2000 x 2000 PIXELS > > Thanks for any help in advance object. Just setting it to nothing will not free the native memory used by the image. Of course, with out seeing the actuall code for this routine, I am only guessing :) -- Tom Shelton [MVP] Hi Tom,
Here is the copy of the code Dim asr As AppSettingsReader = New AppSettingsReader Dim sRemoteDirectory As String = CType(asr.GetValue("RemoteDirectory", GetType(String)), String) Dim sBackupDirectory As String = CType(asr.GetValue("BackupDirectory", GetType(String)), String) Dim img As Image = Image.FromFile(path) Dim imgFormat As Imaging.ImageFormat = GetImageFormat(path) 'Maintain aspect ratio Dim scale As Double = 0 Dim width, height As Integer width = CType(asr.GetValue("ImageWidth", GetType(String)), Integer) height = CType(asr.GetValue("ImageHeight", GetType(String)), Integer) 'Caters for the user specifying 0 for either width or height If width = 0 Then width = 1 ElseIf height = 0 Then height = 1 End If If img.Height < img.Width Then scale = width / img.Width Else scale = height / img.Height End If Dim newwidth As Integer = CInt(scale * img.Width) Dim newheight As Integer = CInt(scale * img.Height) Dim bmp As New Bitmap(img, newwidth, newheight) img.Dispose() 'Add a log entry SaveToLog(filename) Dim sRemotePath As String = String.Format("{0}\{1}", sRemoteDirectory, filename) bmp.Save(sRemotePath, imgFormat) bmp.Dispose() Dim sBackupPath As String = String.Format("{0}\{1}", sBackupDirectory, filename) File.Copy(path, sBackupPath, True) File.Delete(path) Show quoteHide quote "Tom Shelton" <t**@mtogden.com> wrote in message news:1151516355.508204.155570@d56g2000cwd.googlegroups.com... > > Rocky wrote: >> I have a vb.net service which copies images and resizes images from a >> local >> directory to a remote one. >> >> When I drop images into the local directory I get an out of memory error >> after several images - the exception is on the following line. >> >> Dim img As Image = Image.FromFile(path) >> >> The machine has a GB of ram, and there is not a great deal running. >> Each image is about 2000 x 2000 PIXELS >> >> Thanks for any help in advance > > Hmm... My guess would be that you aren't calling Dispose on the image > object. Just setting it to nothing will not free the native memory > used by the image. Of course, with out seeing the actuall code for > this routine, I am only guessing :) > > -- > Tom Shelton [MVP] > |
|||||||||||||||||||||||