473,394 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

VB.NET Service + Out of memory

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
Jun 28 '06 #1
5 5015
Are you rememberring to dispose the Image?

Also have your profiled your app? Depending what you are doing you may be
creating many large objects (which get collected differently). What is the
memory usage of your app if watched through performance monitor?

btw: a 2000x2000 image does use a good deal of memory

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Rocky" <da***********@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP02.phx.gbl...
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

Jun 28 '06 #2
Hi Greg,

Yes, the image is being disposed each time. I will look into the other
things you
mentioned.
"Greg Young" <dr*******************@hotmail.com> wrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
Are you rememberring to dispose the Image?

Also have your profiled your app? Depending what you are doing you may be
creating many large objects (which get collected differently). What is the
memory usage of your app if watched through performance monitor?

btw: a 2000x2000 image does use a good deal of memory

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Rocky" <da***********@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP02.phx.gbl...
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


Jun 29 '06 #3
Here is the code (thought it might help)

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)

"Rocky" <da***********@hotmail.com> wrote in message
news:eH**************@TK2MSFTNGP04.phx.gbl...
Hi Greg,

Yes, the image is being disposed each time. I will look into the other
things you
mentioned.
"Greg Young" <dr*******************@hotmail.com> wrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
Are you rememberring to dispose the Image?

Also have your profiled your app? Depending what you are doing you may be
creating many large objects (which get collected differently). What is
the memory usage of your app if watched through performance monitor?

btw: a 2000x2000 image does use a good deal of memory

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Rocky" <da***********@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP02.phx.gbl...
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



Jun 29 '06 #4
Checked the process it jumps from 8,212 to anywhere between 40,000 and
46,000k

"Rocky" <da***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Here is the code (thought it might help)

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)

"Rocky" <da***********@hotmail.com> wrote in message
news:eH**************@TK2MSFTNGP04.phx.gbl...
Hi Greg,

Yes, the image is being disposed each time. I will look into the other
things you
mentioned.
"Greg Young" <dr*******************@hotmail.com> wrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
Are you rememberring to dispose the Image?

Also have your profiled your app? Depending what you are doing you may
be creating many large objects (which get collected differently). What
is the memory usage of your app if watched through performance monitor?

btw: a 2000x2000 image does use a good deal of memory

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Rocky" <da***********@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP02.phx.gbl...
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



Jun 29 '06 #5
Does it stay there or does it keep gaining if you keep putting in files?
This sounds like fairly normal behavior.

Cheers,

Greg
"Rocky" <da***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
Checked the process it jumps from 8,212 to anywhere between 40,000 and
46,000k

"Rocky" <da***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Here is the code (thought it might help)

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)

"Rocky" <da***********@hotmail.com> wrote in message
news:eH**************@TK2MSFTNGP04.phx.gbl...
Hi Greg,

Yes, the image is being disposed each time. I will look into the other
things you
mentioned.
"Greg Young" <dr*******************@hotmail.com> wrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
Are you rememberring to dispose the Image?

Also have your profiled your app? Depending what you are doing you may
be creating many large objects (which get collected differently). What
is the memory usage of your app if watched through performance monitor?

btw: a 2000x2000 image does use a good deal of memory

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Rocky" <da***********@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP02.phx.gbl...
>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
>
>



Jun 29 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mikael Sorensen | last post by:
I've written a windows service (VB.NET 2003). When running, it consumes between 20-40 MB memory. How do I optimize the memory usage? I've set all objects to Nothing when I'm done using them. ...
8
by: Greg Merideth | last post by:
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem...
5
by: Dave Stienessen | last post by:
Hi all, I have a web service that (for better or worse) returns rather large xmlDataDocuments (up to 150MB) I know - this is huge for a web service call, but this is a service that's used by few...
6
by: ajit | last post by:
I am working on web service which in turn call com components. if # of users using the web service increases. Web service fails is there some why I can prevent max # of concurrent users using the...
8
by: nautonnier | last post by:
I know my problem has been discussed ad nauseum but I still don't get it so please bear with me. I have written a service which performs some work against a database once a day (usually in the...
7
by: HeatherS | last post by:
We are having issues with our windows services using memory and never releasing it. We have one service that has a file watcher which takes an xml file, inserts some records into a database, and...
11
by: sunil | last post by:
Dear All, I have created a .Net service in 2.0 and running it on a machine that has a Quad Processor. It is failing with the following error. "Error 1053: The service did not respond to the start...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
9
by: Ryan Liu | last post by:
Hi, I use C# wrote an Client/Server application. In production environment, will be 130 clients (Windows XP) connect to a Server (Windows 2000/2003 Server) thought TCP/IP socket in a local 100M...
5
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
Hi All, I am using asp.net session state service to store session. The concurrent online user will be almost 2000. Could asp.net session state service afford this? Is there any limitation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.