C# how to prevent outofmemoryexeption

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

JasonCoder

Golden Member
Feb 23, 2005
1,893
1
81
Originally posted by: Crusty
Originally posted by: Dhaval00
Originally posted by: Crusty
I'm curious to know how long your string was when it crashed. Using a StringBuilder I was able to build a 137million length string before I got the exception, Task manager reported ~500MB usage.

If you look at the Console in the picture or while running the app, it actually shows the length of the string at the end of every iteration. In that screenshot, it was specifically 281,511,074. As a side note, up on reaching that limit, the application would come to a crawl before throwing the exception.

Lol oops... how could I have missed that link :p


After reading some of the OP's post in more detail, I would suggest altering how you are storing your data.

Why not use the built-in serialization of .NET to store your data in flat files and store references to the flat files in the database. You get the best of both worlds. If you want to store your actual data in the database then you should use more then one field for an entire objects data... that kinda defeats the purpose of using a relational DB.

This.