473,804 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is OutOfMemoryExce ption thrown?

I can't figure out why once or twice per week, my C# server application
throws OutOfMemoryExce ptions. There is plenty of memory in the machine. As
far as I can tell, when the exception is thrown, only 400 megs of 1gig total
is in use.

The exception is thrown while trying to update List<>. Here's a bit of the
stack trace:

===
System.OutOfMem oryException: Exception of type 'System.OutOfMe moryException'
was thrown.
at System.Collecti ons.Generic.Lis t`1.set_Capacit y(Int32 value)
at System.Collecti ons.Generic.Lis t`1.EnsureCapac ity(Int32 min)
at System.Collecti ons.Generic.Lis t`1.Add(T item)
at Mosaic.Core.Sta tUtils.ExtractR ORs(MiniPerfIte m[] perfItems, Int32
startIdx, Int32 endIdx, Boolean useNAOnNonPosBa l) in
C:\Development\ Mosaic\Mosaic-AM\Mosaic.Core. Shared\Code\Uti lities\Statisti cal\StatUtils.c s:line
38
===

I have a lot of small objects in memory at the time of the exception but I'm
nowhere close to exhausting available RAM. Any ideas?

Oct 11 '07
19 2052
On Oct 12, 2:03 pm, "Lamont Sanford" <yaBigDu...@san ford.sonwrote:
Can I suggest that you use perfmon to look at both the heap and the
handle count of your process?

Sure, I'll check it out. I've never used permon before. What signs/symptoms
should I be looking for?
Handles or heap memory rising constantly would be generally bad - but
you can also add performance traces for various .NET aspects, which
can be handy.

Jon

Oct 12 '07 #11
"Lamont Sanford" <ya********@san ford.sonwrote in message
news:MN******** *************** *******@giganew s.com...
>
>Maybe due to extensively allocating and freeing memory, your memory is
too much fragmentized ?

How would I go about defragmenting it? Should I manually run a garbage
collection?

No, there is nothing you can do about a fragmented heap (both managed and
process heap), other than restart the server.
Of course it's up to you to prevent possible heap fragmentation as much as
possible.
Therefore, I would like to know what version of the Framework and OS you
are running this on?
How large are the Lists in bytes, if you say up to 100k, do you mean 100kb
or something else, how did you measure this size?
How many of these list do you possibly create simultaneously?
Are you using Sockets connections?
Do you explicitly pin objects, or do you call into unmanaged code?

Willy.

Oct 12 '07 #12
I got the same problem before. Then I rewrited the application by replacing
DataSet by SqlDataReader.

"Lamont Sanford" <ya********@san ford.sonwrote in message
news:b_******** *************** *******@giganew s.com...
>I can't figure out why once or twice per week, my C# server application
throws OutOfMemoryExce ptions. There is plenty of memory in the machine. As
far as I can tell, when the exception is thrown, only 400 megs of 1gig
total is in use.

The exception is thrown while trying to update List<>. Here's a bit of the
stack trace:

===
System.OutOfMem oryException: Exception of type
'System.OutOfMe moryException' was thrown.
at System.Collecti ons.Generic.Lis t`1.set_Capacit y(Int32 value)
at System.Collecti ons.Generic.Lis t`1.EnsureCapac ity(Int32 min)
at System.Collecti ons.Generic.Lis t`1.Add(T item)
at Mosaic.Core.Sta tUtils.ExtractR ORs(MiniPerfIte m[] perfItems, Int32
startIdx, Int32 endIdx, Boolean useNAOnNonPosBa l) in
C:\Development\ Mosaic\Mosaic-AM\Mosaic.Core. Shared\Code\Uti lities\Statisti cal\StatUtils.c s:line
38
===

I have a lot of small objects in memory at the time of the exception but
I'm nowhere close to exhausting available RAM. Any ideas?



Oct 12 '07 #13
Try using LinkedList<inst ead of List<if you can. It won't be as
efficient at stopping memory fragmentation, but it will not call the
EnsureCapacity function, which, in essence, momentarily triples the
amount of memory used so that it can double the amount of memory used.
Okay, so it's not really "memory used" unless you're using structs.
It's memory used for pointers, which on a 32bit system for 100k should
400kilobytes -- not much! (Tripling that should be fine which makes me
wonder if it's a list of structs.)

Oct 12 '07 #14
Therefore, I would like to know what version of the Framework and OS you
are running this on?
I'm running .NET Framework 2.0 (VS 2005) on Win2003.
How large are the Lists in bytes, if you say up to 100k, do you mean 100kb
or something else, how did you measure this size?
I just meant that the size of the list (List<T>.Count) would never exceed
100,000. If type 'T' is a double and double requires 8 bytes, the total
required memory shouldn't exceed 800,000 bytes... and I have hundreds of
gigs free.
How many of these list do you possibly create simultaneously?
Only one can exist at a time, but these lists will be created over and over
again with different values.When a list is no longer needed, it isn't
explicitly Clear()'d, but it does fall out of scope so it should be GCd.
Are you using Sockets connections?
Yes, sockets are used. No more than 30 inbound connections are active at any
given time.
Do you explicitly pin objects, or do you call into unmanaged code?
What does "pin" mean? No, I don't make any calls into unmanaged code.
Oct 15 '07 #15
"Lamont Sanford" <ya********@san ford.sonwrote in message
news:dP******** *************** *******@giganew s.com...
>Therefore, I would like to know what version of the Framework and OS you
are running this on?

I'm running .NET Framework 2.0 (VS 2005) on Win2003.
>How large are the Lists in bytes, if you say up to 100k, do you mean
100kb or something else, how did you measure this size?

I just meant that the size of the list (List<T>.Count) would never exceed
100,000. If type 'T' is a double and double requires 8 bytes, the total
required memory shouldn't exceed 800,000 bytes... and I have hundreds of
gigs free.
No you don't? The virtual memory space attributed to your process is only
2GB (supposing W2K3 32 bit). That means that you cannot allocate more than
this space for managed objects minus the space allocated by the application
the runtime and the Framework data and code, this leaves you with less than
1.6GB (non contiguous) in the most optimal case at process creation time.
Now, 800 Kb is not a big deal, but as these objects are larger than 85Kb,
they end on the LOH and as this one is never compacted, you may end with a
highly fragmented heap, if you don't tput an eye on object life time.
>How many of these list do you possibly create simultaneously?

Only one can exist at a time, but these lists will be created over and
over again with different values.When a list is no longer needed, it isn't
explicitly Clear()'d, but it does fall out of scope so it should be GCd.
Yes, but that doesn't mean that only one can exist at a time, the GC doesn't
run deterministical ly.
>Are you using Sockets connections?

Yes, sockets are used. No more than 30 inbound connections are active at
any given time.
>Do you explicitly pin objects, or do you call into unmanaged code?

What does "pin" mean? No, I don't make any calls into unmanaged code.
Yes, you do (indirectly), there is no single managed application in the
world that don't call in unmanaged code. The socket classes need to pin the
send/reeive buffers when calling into the native Winsock API's. Pinning is
there to prevent the heap allocated object to move in memory when the GC
runs, however, pinning also prevents compactation of the GC heap.
Does it happen that these buffers have something in common with the above
mentioned List's?

Anyway, I would suggest you to inspect your memory allocation pattern by
running your code against a memory profiler.

Willy.
Oct 15 '07 #16
>I just meant that the size of the list (List<T>.Count) would never exceed
>100,000. If type 'T' is a double and double requires 8 bytes, the total
required memory shouldn't exceed 800,000 bytes... and I have hundreds of
gigs free.

No you don't?
Ooops, I meant hundreds of megs, not hundreds of gigs... sorry for the
typeo.

Thanks for the hints. I'll take your advice and hopefully I can get to the
bottom of this.
Oct 15 '07 #17

Hi Lamont,
What is the Database engine that your app is interacting with?
Bob
On Thu, 11 Oct 2007 13:30:16 -0500, "Lamont Sanford"
<ya********@san ford.sonwrote:
>I can't figure out why once or twice per week, my C# server application
throws OutOfMemoryExce ptions. There is plenty of memory in the machine. As
far as I can tell, when the exception is thrown, only 400 megs of 1gig total
is in use.

The exception is thrown while trying to update List<>. Here's a bit of the
stack trace:

===
System.OutOfMe moryException: Exception of type 'System.OutOfMe moryException'
was thrown.
at System.Collecti ons.Generic.Lis t`1.set_Capacit y(Int32 value)
at System.Collecti ons.Generic.Lis t`1.EnsureCapac ity(Int32 min)
at System.Collecti ons.Generic.Lis t`1.Add(T item)
at Mosaic.Core.Sta tUtils.ExtractR ORs(MiniPerfIte m[] perfItems, Int32
startIdx, Int32 endIdx, Boolean useNAOnNonPosBa l) in
C:\Development \Mosaic\Mosaic-AM\Mosaic.Core. Shared\Code\Uti lities\Statisti cal\StatUtils.c s:line
38
===

I have a lot of small objects in memory at the time of the exception but I'm
nowhere close to exhausting available RAM. Any ideas?

Oct 17 '07 #18
>
Hi Lamont,
What is the Database engine that your app is interacting with?
Bob
I'm using SQL Server 2005.
Oct 17 '07 #19
bob
OK.
Not what I thought.
I had weird problem with SQL Anywhere Version 9 that appeared as a
memory problem.
Sorry no other ideas.
Bob

On Wed, 17 Oct 2007 08:20:12 -0500, "Lamont Sanford"
<ya********@san ford.sonwrote:
>>
Hi Lamont,
What is the Database engine that your app is interacting with?
Bob

I'm using SQL Server 2005.
Oct 17 '07 #20

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

Similar topics

2
764
by: Peter Aberline | last post by:
Hi all, We have written a C # .NET application and we're encountering memory problems in the form of System.OutOfMemoryException. Our application creates many thousands of objects in a temporary in memory store, which uses a lot of runtime memory. Not an ideal situation, but an acceptable short term solution given our project constraints.
0
2782
by: Per Bergland | last post by:
After many woes, I finally managed to get a stack dump of my System Service (written in C#) that insists on crashing when launched at system boot time (see below on how to get this dump - I couldn't find any info on how to do this). Here's the stack trace from cordbg: Unhandled exception generated: (0x04719c94) <System.Runtime.Remoting.RemotingException> _className=<null> _exceptionMethod=<null>
2
3276
by: Fernando Casero | last post by:
Hi, I'm programming on Visual C# Express Beta 2 and I have the following code: class MyClass { int a = new int int b = new int public int SomeMethod() }
1
3455
by: Ripul Handa | last post by:
Hi We are running IIS 5.0 cluster with cisco local director. We are running a website on 2 webservers and I have been observing that from past few days we have are getting this error message of and on Error Messag Remote IP:66.122.242.6 Host:216.211.212.2
1
4996
by: SMG - Idealake | last post by:
Hi all, I am getting following error on my error, what could be the reason? Exception of type System.OutOfMemoryException was thrown. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.OutOfMemoryException: Exception of type System.OutOfMemoryException was thrown.
2
3948
by: Dave | last post by:
We just started getting this error message in our application today (stack trace below). From the OutOfMemoryException, I'm guessing it could be a memory leak. I'm making sure I'm closing all my connections in the finally block but I'm not sure what I should be doing. As far as the "Unable to serialize the session state" error, this app has been running for days and this is the first I've seen this one as well. Any thoughts would be...
1
3900
by: Ashkan Daie | last post by:
Hi All, When trying to install a performance counter via InstallUtil I get the following exception: Creating performance counter category Enterprise Library Caching. An exception occurred during the Install phase. System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was
8
12575
by: =?Utf-8?B?UGlnZ3k=?= | last post by:
Hi to all, I am getting this System.OutOfMemoryException calling the Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(<stream>,<Obj>) method. The type of <streamis IO.MemoryStream =====Exception: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
16
22249
by: Lamont Sanford | last post by:
I can't figure out why once or twice per week, my C# server application throws OutOfMemoryExceptions. There is plenty of memory in the machine. As far as I can tell, when the exception is thrown, only 400 megs of 1gig total is in use. The exception is thrown while trying to update List<>. Here's a bit of the stack trace: === System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException'
1
1865
by: netwapps | last post by:
I have: Application Type: Web application with VB.net 1.1 WebServer: IIS6 Machine Server: Windows 2003 The User opens 4-5 browsers connecting to the application and clicks on the Autorefresh button. This button puts javascript code in the page that will cause the page to Automatically refresh every x amount of minutes. after about 4-5 times of refreshing the browser will come back with this error: In 2 pages: [HttpException...
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.