Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.OutOfMemoryException

Status
Not open for further replies.

JLizOB

Programmer
Dec 5, 2007
45
CA
Hi,
I have a program that opens a database and fills a datatable, with 0 rows, through a dataadapter. A text file is then parsed and the datatable has rows inserted into it with each row from the text file. When the program is done parsing the file and modifying the datatable, the dataadapter's update method is called and the database is updated. The program handles 2MB size text files fine, but when I put larger files such as 147MB files it errors out, as it is parsing the text file and updating the datatable, with a System.OutOfMemory error. What can I do to fix this? Is my only option to periodically call the adapter's update method and clear out the datatable, then continue parsing the text fiel?
 
How much memory is in your system? A windows application can have a max of 2GB of RAM to use unless you enable the /3GB switch which allows an application to enter a 3rd GB of shared memory - but not reliably.

You may want to consider breaking the file up into smaller files, clear your dataadapter after each file and do it that way. Sure there's a bit of a performance hit but is it that critical?

 
As an added note - make sure you are disposing of all non-managed resources (such as files) correctly. Close streams and call Dispose().

You may even need a GC.Collect() to force garbage collection before running your update.

 
I remember reading some posts a while back about framework 1.1 having memory related issues. IIRC there was an update or service pack or whatever microsoft was calling it to fix this. Have you updated the framework????
 
Thanks for your reply everyone. I ended up breaking everything up on the fly. The rowcount of the datatable gets checked every so often when the file is being processed and once the row count gets to 100,000 I call the dataadapter update method, clear the datatable and continue processing.
 
You can also get this error by uncontrolled recursion.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top