Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Memory error

Posted on 2007-11-16
15
Medium Priority
?
207 Views
Last Modified: 2013-12-17
Hi Experts,

Below is the code. I have 3 tables, the second table contains 100,000 rows ,its afiling at RenderControl with the
execption : Exception of type System.OutOfMemoryException was thrown.
Please advise.
foreach (Table table in tables)
{
StringWriter sw = new StringWriter(output);
HtmlTextWriter htw = new HtmlTextWriter(sw);
table.RenderControl(htw);
}

Open in new window

0
Comment
Question by:Bkuniyil
  • 7
  • 6
  • 2
15 Comments
 
LVL 16

Expert Comment

by:McExp
ID: 20300184
What actually is the code trying to do?
0
 

Author Comment

by:Bkuniyil
ID: 20300219
Will finally save to a file
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20300252
you have to write directly to file. Associate your writer with a FileStream.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 16

Expert Comment

by:McExp
ID: 20300315
What he said!
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20300421
try with this:

TextWriter sw =  new StreamWriter("somefile.html");
HtmlTextWriter htw = new HtmlTextWriter(sw);
 
foreach (Table table in tables)
{
     table.RenderControl(htw);
}
htw.Close();

Open in new window

0
 

Author Comment

by:Bkuniyil
ID: 20301532
The above code still saves only part of the data to the file "somefile.html"
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20301549
what do you mean with "part of the data" ?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20301581
try to use Flush:
TextWriter sw =  new StreamWriter("somefile.html");
HtmlTextWriter htw = new HtmlTextWriter(sw);
 
foreach (Table table in tables)
{
     table.RenderControl(htw);
     htw.Flush();
}
htw.Close();
0
 

Author Comment

by:Bkuniyil
ID: 20350736
I need to write the loop through each of the tables and write it to the StringBuilder object. Is there any way of doing it without writing it to a file?
StringBuilder output = new StringBuilder();
foreach (Table table in tables)
{
StringWriter sw = new StringWriter(output);
HtmlTextWriter htw = new HtmlTextWriter(sw);
table.RenderControl(htw);
}

Open in new window

0
 

Author Comment

by:Bkuniyil
ID: 20352428
Is there a maximum value that a StringBuilder Object can hold, i get an Out of Memory error.Appreciate all help.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20352525
capacity of a StringBuilder class is 4GB.
0
 

Author Comment

by:Bkuniyil
ID: 20352597
The file i am trying to build through the Stringbuilder object is  2MB file, it should work alright?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20352888
Yes, it should, unless something bad in your loop
0
 

Author Comment

by:Bkuniyil
ID: 20355586
The code in the loop is pasted above.Please advise
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 20355637
>> the second table contains 100,000 rows
assuming each rows consumes 2Kb in unicode, we are talking of about 200,000,000 = 200 Mb of text. But during html construction, maybe you will need even more memory, maybe up to 1 GB, this is too much heavy for any standard computer. I think it is no sense to try to do this in memory, you have to render directly to a file stream.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question