memory leak in streamwriteR? help...

R

Rob Corwin

Hi,
a c# app of mine that parses 30,000 xml files writes large
amounts of data to flat file (> 2GB) using a streamwriter
object (sw). everything works fine except that the memory
used by the app grows linearly during execution and
eventually crashes the computer. without going into too
much detail of my code, i made the following observations:

- if you comment out the sw.Write(x) statement (which is
inside the loop that parses the xml files), memory doesn't
increase. thus it must be something to do with the
streamwriter or file I/O.

- if you change x in sw.Write(x) to be a constant, memory
doesn't increase, but if x is an expression or variable,
memory does increase. Not sure what this means.

I've tried many things to solve this problem and am
completely stuck. I've tried making sw = null every so
often within the loop, making a new streamwriter and
output file (so that the file sizes never exceed 10MB),
and calling GC.Collect() to try and force the compiler to
clean up memory, but there is no effect. I've tried using
{} statements which don't do anything either. The only
thing I can think of is to re-run the entire application
multiple times and pass command line parameters to
indicate where the last one left off, but this is
obviously not an ideal solution.

I did get it to work by using the
Scripting.FileSystemObejct via COM instead of
streamwriter, but it's prohibitively slow. However this
does indicate that there are no memory leaks within the
rest of my code, and that the problem is with streamwriter
somehow.

Any thoughts? Any help at all is greatly appreciated!!!!!!!
thanks in advance
Rob
 
P

Peter Koen

Hi,
[..]


Any thoughts? Any help at all is greatly appreciated!!!!!!!
thanks in advance

This is a known bug in the StreamWriter class in the Framework Version 1.0
and 1.1

You can expect a fix with .NET Framework 2.0 It's very unlikly that there
will be an additional servicepack for 1.1 before the release of 2.0
 
P

Peter Koen

It's very unlikly that there
Just curious to hear where you get this from?

Willy.

Had the same problem and needed about 2 weeks of telephoning around until I
got a ms guy to tell me what I found out by myself: yes this is a bug.
 
R

Robert Corwin

thanks guys... someone else had the same experience as you Peter, he
called a million people and finally found out that it is a bug. at
least i only wasted 3 days.... apparently there are similar problems
with System.Data.DataSet objects that are very large.
 
Y

Yan-Hong Huang[MSFT]

Hello All,

Koen: Do you mean you have called Microsoft Support Service on this issue
and the support engineer told you that? Could you please post the support
incident ID here? I will go ahead to check it and hope to post more
information on it here.

Robert: Another thing you may try is to call:
// This method call triggers the garbage collector
// to collect the unreferenced memory.
GC.Collect();
// Wait for the GC's Finalize thread to finish
// executing all queued Finalize methods.
GC.WaitForPendingFinalizers();

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top