473,790 Members | 2,850 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 #1
16 22247
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.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?
Do you have any idea how big the list is at the point of failure?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 11 '07 #2
OutOfMemoryExce ption really means "out of resources". Are you opening files
and not disposing them or something?

http://mrpmorris.blogspot.com/2006/1...maybe-not.html


Oct 11 '07 #3
Do you have any idea how big the list is at the point of failure?
>
At max it could get up to the tens of thousands, but certainly never over
100k...
Oct 11 '07 #4
OutOfMemoryExce ption really means "out of resources". Are you opening
files and not disposing them or something?

http://mrpmorris.blogspot.com/2006/1...maybe-not.html
Interesting. I'll check out the article.

No, I don't make use of files to any major extent, but I do use a lot of
database connections. Maybe I'm not closing them properly?
Oct 11 '07 #5
Most likely - improperly closed / disposed connection objects means you run
out of Connection Pool connections, which can cause exceptions similar to
what you're seeing - especially if combined with other code.

1) use the same connection string througout your app.
2) open a connection just before you need to do database call.
3) close the connection immediately after - this returns it to the pool
4) be very careful with DataReaders as they hold open a connection.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Lamont Sanford" wrote:
OutOfMemoryExce ption really means "out of resources". Are you opening
files and not disposing them or something?

http://mrpmorris.blogspot.com/2006/1...maybe-not.html

Interesting. I'll check out the article.

No, I don't make use of files to any major extent, but I do use a lot of
database connections. Maybe I'm not closing them properly?
Oct 11 '07 #6
Lamont Sanford <ya********@san ford.sonwrote:
Do you have any idea how big the list is at the point of failure?

At max it could get up to the tens of thousands, but certainly never over
100k...
That sounds unlikely to be the issue then.

Can I suggest that you use perfmon to look at both the heap and the
handle count of your process?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 11 '07 #7
Lamont Sanford pisze:
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?
Maybe due to extensively allocating and freeing memory, your memory is
too much fragmentized ?

Regards
Oct 11 '07 #8
>
That sounds unlikely to be the issue then.

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?
Oct 12 '07 #9
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?
Oct 12 '07 #10

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

Similar topics

1
4995
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.
8
12574
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.
19
2051
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'
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
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
9986
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
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...
0
6769
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();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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.