Exception of type 'System.OutOfMemoryException' was thrown

Posted by Jeena under C# on 7/10/2012 | Points: 10 | Views : 42494 | Status : [Member] | Replies : 5
Hi all,


I have a windows application developed in framework 2.0.
I need to export 300000 from a mysql database need some formatting and write into CSV file.
For that i am doing the following steps

1. Read data from database to a data set
2. Reads the data by datarow [ foreach (DataRow drExport in dsToExportgeneral.Rows)}
3. Will do some formatting and write into another dataset
4.Then will write the formatted dataset as a csv file

Am getting error "System.OutOfMemoryException" after reading around 60000 records..

Is there any way to fix this issue

Thanks
Jeena




Responses

Posted by: Ranjeet_8 on: 7/10/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
refer this url, it will help u

http://stackoverflow.com/questions/356645/exception-of-type-system-outofmemoryexception-was-thrown-why

Jeena, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muralidosscm on: 7/10/2012 [Member] Starter | Points: 25

Up
0
Down
http://msdn.microsoft.com/en-us/library/system.outofmemoryexception.aspx

Regards
Muralidoss M

Jeena, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mallesh on: 7/10/2012 [Member] Starter | Points: 25

Up
0
Down
There are mainly two reasons for getting the System.OutOfMemoryException

1. Your process takes lot of memory (<= 800MB.)
2. The space of virtual address fragmented, reducing, contiguous allocation.
And sometimes combination of both leads to that error.

To avoid the fragmentation .NET provides batch compilation feature. If batch compilation is enabled, .NET will dynamically compile each folder into a single DLL when the application is JITted. If batch compilation is not enabled, each page and user control is compiled into a separate DLL that is then loaded into the address space for the process. This results into the amount of contiguous free memory, leads to avoid OutOfMemoryException in greater manner.

When you deploy your application, you need to make sure that you set the debug attribute in the web.config file to false as follows.

<compilation debug="false" />


If you would like to ensure that debug is disabled on your production server regardless of the setting in the web.config file, you can use the <deployment> element introduced in .NET. This element should be set in the machine.config file as follows.

<configuration>
<system.web>
<deployment retail="true" />
</system.web>
</configuration>


Adding this setting to your machine.config file will override the debug attribute in any web.config file on the server.

I hope that this information will help you to identify memory problems in your ASP.NET application that can lead to OutOfMemoryExceptions.
Happy Coding...!

Mallesh

== Mallesh

Jeena, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sumit.Bundiwal on: 7/10/2012 [Member] Starter | Points: 25

Up
0
Down
you can do extend the connection time . or you can get row in a group of rows like 1000 and call this by looping

sumit bundiwal

Jeena, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mias on: 11/7/2012 [Member] Starter | Points: 25

Up
0
Down
Being able to store information for users and for the application in server memory is really awesome. I have in the past abused it a little and at on point I had a web application which would actually throw a OutOfMemory exception every now and then. I started searching for tool which would help me analyze session objects and application state objects. After an extensive search, I came accross the Asp.Net Web Profiler, which allows for viewing session variable values which has been declared in different sessions and their sizes to be particular. It displays variables and objects which has been declared in the application state, the current session state as well as in all user sessions and the asp.net cache. You can download it from www.aspwebprofiler.com

It also alows for drill down into object properties in order to detect large objects and optimizing them for memory usage. This way I could detect large sessions and realized that I had the same large object which runs in every user session. I moved it to the application state and my problem was solved.

Jeena, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response