473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

streamwriter consumes memory??

Jon
I'm puzzled..
let's say I have an array of streamwriters. a lot..

'the code is something like
dim sw() as streamwriter
redim sw(10000)

'instantiate
for i as int16 = 0 to 9999
sw(i) = new streamwriter(arrayOfFileName(i))
next
'write to the files
for i as int16 = 0 to 9999
sw(i).write("123 ")
next

I monitor the memory from task manager. I can understand
that memory level drops when I instantiate the
streamwriters.
However, I cannot understand, during the streamwriter
writing to the files, the memory drops with each write.

I tried closing all the streamwriters after the
writing... but the memory is not released. is it waiting
for GC?

Anyone knows how I can free the memory so I don't run out
of memory half-way thru writing the files?
Nov 20 '05 #1
8 3253
Why you need a lot of StreamWriters, it's a waste of memory, in the example
you show us, you only write one file at time, why not use only 1 stream
writer?

--
Bela Istok
MVP C#
Caracas, Venezuela
"Jon" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
I'm puzzled..
let's say I have an array of streamwriters. a lot..

'the code is something like
dim sw() as streamwriter
redim sw(10000)

'instantiate
for i as int16 = 0 to 9999
sw(i) = new streamwriter(arrayOfFileName(i))
next
'write to the files
for i as int16 = 0 to 9999
sw(i).write("123 ")
next

I monitor the memory from task manager. I can understand
that memory level drops when I instantiate the
streamwriters.
However, I cannot understand, during the streamwriter
writing to the files, the memory drops with each write.

I tried closing all the streamwriters after the
writing... but the memory is not released. is it waiting
for GC?

Anyone knows how I can free the memory so I don't run out
of memory half-way thru writing the files?

Nov 20 '05 #2
Why you need a lot of StreamWriters, it's a waste of memory, in the example
you show us, you only write one file at time, why not use only 1 stream
writer?

--
Bela Istok
MVP C#
Caracas, Venezuela
"Jon" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
I'm puzzled..
let's say I have an array of streamwriters. a lot..

'the code is something like
dim sw() as streamwriter
redim sw(10000)

'instantiate
for i as int16 = 0 to 9999
sw(i) = new streamwriter(arrayOfFileName(i))
next
'write to the files
for i as int16 = 0 to 9999
sw(i).write("123 ")
next

I monitor the memory from task manager. I can understand
that memory level drops when I instantiate the
streamwriters.
However, I cannot understand, during the streamwriter
writing to the files, the memory drops with each write.

I tried closing all the streamwriters after the
writing... but the memory is not released. is it waiting
for GC?

Anyone knows how I can free the memory so I don't run out
of memory half-way thru writing the files?

Nov 20 '05 #3
hi Bela,

everytime some data comes in, I want to write(and append)
these data to the many files. Also, I don't want to close
these files. I want to append the data. Finally when the
data stops coming in, I can close these files, and will
get the final files.

if I write to these files one by one, each time the data
comes in,
sw.open
sw.write
sw.close,
it will take forever.
-----Original Message-----
Why you need a lot of StreamWriters, it's a waste of memory, in the exampleyou show us, you only write one file at time, why not use only 1 streamwriter?

--
Bela Istok
MVP C#
Caracas, Venezuela

Nov 20 '05 #4
hi Bela,

everytime some data comes in, I want to write(and append)
these data to the many files. Also, I don't want to close
these files. I want to append the data. Finally when the
data stops coming in, I can close these files, and will
get the final files.

if I write to these files one by one, each time the data
comes in,
sw.open
sw.write
sw.close,
it will take forever.
-----Original Message-----
Why you need a lot of StreamWriters, it's a waste of memory, in the exampleyou show us, you only write one file at time, why not use only 1 streamwriter?

--
Bela Istok
MVP C#
Caracas, Venezuela

Nov 20 '05 #5
As far as i know, .Close() isn't the same as calling the Garbage Collection.
if you set the Variable to nothing the memory will release the next time
around the GC runs
If you call the .Dispose() method, then GC will immediatly clean up and
release memory. (i don't remember is StramWriter implements iDispose)

Read about Dispose and Nothing in the MSDN documentation.
"Jon" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
I'm puzzled..
let's say I have an array of streamwriters. a lot..

'the code is something like
dim sw() as streamwriter
redim sw(10000)

'instantiate
for i as int16 = 0 to 9999
sw(i) = new streamwriter(arrayOfFileName(i))
next
'write to the files
for i as int16 = 0 to 9999
sw(i).write("123 ")
next

I monitor the memory from task manager. I can understand
that memory level drops when I instantiate the
streamwriters.
However, I cannot understand, during the streamwriter
writing to the files, the memory drops with each write.

I tried closing all the streamwriters after the
writing... but the memory is not released. is it waiting
for GC?

Anyone knows how I can free the memory so I don't run out
of memory half-way thru writing the files?

Nov 20 '05 #6
As far as i know, .Close() isn't the same as calling the Garbage Collection.
if you set the Variable to nothing the memory will release the next time
around the GC runs
If you call the .Dispose() method, then GC will immediatly clean up and
release memory. (i don't remember is StramWriter implements iDispose)

Read about Dispose and Nothing in the MSDN documentation.
"Jon" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
I'm puzzled..
let's say I have an array of streamwriters. a lot..

'the code is something like
dim sw() as streamwriter
redim sw(10000)

'instantiate
for i as int16 = 0 to 9999
sw(i) = new streamwriter(arrayOfFileName(i))
next
'write to the files
for i as int16 = 0 to 9999
sw(i).write("123 ")
next

I monitor the memory from task manager. I can understand
that memory level drops when I instantiate the
streamwriters.
However, I cannot understand, during the streamwriter
writing to the files, the memory drops with each write.

I tried closing all the streamwriters after the
writing... but the memory is not released. is it waiting
for GC?

Anyone knows how I can free the memory so I don't run out
of memory half-way thru writing the files?

Nov 20 '05 #7
Actually, calling .Dispose() will release any resources the object is
holding, but will not cause the GC to clean up immediately.

To clean up after these, just make sure you call .dispose() as soon as you
can, and do not hold references to them. the garbage collector will
automatically reclaim the memory when the "pressure" is high enough (the
system is running low). You can also force a collection by calling
GC.Collect()
"Jarod_24" <ja******@hotmail.com> wrote in message
news:64******************************@news.teranew s.com...
As far as i know, .Close() isn't the same as calling the Garbage Collection. if you set the Variable to nothing the memory will release the next time
around the GC runs
If you call the .Dispose() method, then GC will immediatly clean up and
release memory. (i don't remember is StramWriter implements iDispose)

Read about Dispose and Nothing in the MSDN documentation.
"Jon" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
I'm puzzled..
let's say I have an array of streamwriters. a lot..

'the code is something like
dim sw() as streamwriter
redim sw(10000)

'instantiate
for i as int16 = 0 to 9999
sw(i) = new streamwriter(arrayOfFileName(i))
next
'write to the files
for i as int16 = 0 to 9999
sw(i).write("123 ")
next

I monitor the memory from task manager. I can understand
that memory level drops when I instantiate the
streamwriters.
However, I cannot understand, during the streamwriter
writing to the files, the memory drops with each write.

I tried closing all the streamwriters after the
writing... but the memory is not released. is it waiting
for GC?

Anyone knows how I can free the memory so I don't run out
of memory half-way thru writing the files?


Nov 20 '05 #8
If you have trouble with the memory used you need to limit the number or classes that you instance, because each class use some memory and resources from the machine.



I think that you can implement something like a queue, were all the info from the files get in a temporal buffer (0nly 1 queue with all the pending info), and later you write the info in the files, 10 at time, or something like that. I guest that it's a better approach that have 1000 Streams Writers opened all the time because you don't write all the time to the Streams Writers.
--
Bela Istok
MVP C#
Caracas, Venezuela
<an*******@discussions.microsoft.com> wrote in message news:09****************************@phx.gbl...
hi Bela,

everytime some data comes in, I want to write(and append)
these data to the many files. Also, I don't want to close
these files. I want to append the data. Finally when the
data stops coming in, I can close these files, and will
get the final files.

if I write to these files one by one, each time the data
comes in,
sw.open
sw.write
sw.close,
it will take forever.
-----Original Message-----
Why you need a lot of StreamWriters, it's a waste of memory, in the exampleyou show us, you only write one file at time, why not use only 1 streamwriter?

--
Bela Istok
MVP C#
Caracas, Venezuela

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tom L | last post by:
Like the subject says, how do I figure out how much memory an object takes.. If I create an employees collection, which is a collection of employee objects, and I load up a handful of records, I...
6
by: Bob Rock | last post by:
Hello, I've noticed that after calling the Close method on a StreamWriter, I get exceptions on any operation I might request on the associated stream (with a message "Cannot access a closed...
13
by: Rob Corwin | last post by:
Hi, a c# app of mine that parses 30,000 xml files writes large amounts of data to file (> 2GB) using a streamwriter object (sw). everything works fine except that the memory used by the app grows...
5
by: Rob Corwin | last post by:
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...
11
by: LordHog | last post by:
Hello, I recently wrote an application that is used for testing units in a burn-in chamber. It uses two external library that require the use of P\Invoke in order to work with them. There is a...
0
by: Jon | last post by:
I'm puzzled.. let's say I have an array of streamwriters. a lot.. 'the code is something like dim sw() as streamwriter redim sw(10000) 'instantiate for i as int16 = 0 to 9999 sw(i) = new...
1
by: iwdu15 | last post by:
hi...just a quick question. what are the differences in using a FileStream and StreamWriter opposed to just a StreamWriter.....for instance Dim fs as New FileStream("C:\Test.txt",...) Dim sw As...
1
by: Merk | last post by:
In a 2.0 Windows Forms app... in a static class I have a method named WriteToLocalLog() that writes to a text file on the local machine. I declare a StreamWriter at the class level (not inside...
12
by: Tony | last post by:
Hi expert, I installed DB2 v8.2 server on Solaris 9 box. When I connect to DB2 using control centre or other applications(except command line), around 12 db2sysc processes pop up and each one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.