I want to create multiple FileStreams
and need to keep them open - there will be no I/O operations. What will be the memory consumption? If I create large number of such streams will this effect system performance?
In short: It is not a good idea to keep File Streams open, because it is un-managed resource.
In .NET framework architecture all un-managed resources cause memory big leaks, if NOT managed correctly in the code.
If you are saying - "I don't want to just let it go out of scope. Then the garbage collector will eventually call the Dispose, killing the stream. But i want to keep the stream open."
Garbage collector will call the Finalize
method (destructor), not the Dispose
method. The finalizer will call Dispose(false)
which will not dispose the underlying stream. You should be OK by leaving the StreamReader
go out of scope if you need to use the underlying stream directly. Just make sure you dispose the underlying stream manually when it's appropriate.