Another question about memory : System.IO.StringWriter and Dispose

F

fabrice

Re hello,

I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to export
in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :

example :

Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
....
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing

BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
As Boolean)' is not accessible in that context. it is protected..


I can use the Close() method but i m not sure that this last one have the
same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object


Thanks for you help
fabrice
 
C

Cor Ligthert [MVP]

Fabrice,

The overloaded version you use is meant for the Idispose itself and not for
direct use.

You can rely on the standard version or just the quicker one, the close.

(setting it to nothing is absolute without any sense after the close, where
I assume that you have instanced in the method, and otherwise should try to
do that).

Cor
 
M

Miha Markic [MVP C#]

Call Dispose() and then set variable to nothing (the later might just speed
it up a bit or not) - that is the quickest way.
 
C

Cor Ligthert [MVP]

Miha, it is normally slower, although it is probably only a clock tick.

I have however seen that C# programmers have more the habit to declare
global than VB.Net programmers do. In that global situation it makes sense.

Cor

Miha Markic said:
Call Dispose() and then set variable to nothing (the later might just
speed it up a bit or not) - that is the quickest way.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

fabrice said:
Re hello,

I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to
export in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :

example :

Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing


BC30390: 'System.IO.StringWriter.Protected Overrides Sub
Dispose(disposing As Boolean)' is not accessible in that context. it is
protected..


I can use the Close() method but i m not sure that this last one have the
same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object


Thanks for you help
fabrice
 
M

Miha Markic [MVP C#]

Why do you think it is slower? It releases reference to the instance and
thus it is immediately available for GC.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Cor Ligthert said:
Miha, it is normally slower, although it is probably only a clock tick.

I have however seen that C# programmers have more the habit to declare
global than VB.Net programmers do. In that global situation it makes
sense.

Cor

Miha Markic said:
Call Dispose() and then set variable to nothing (the later might just
speed it up a bit or not) - that is the quickest way.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

fabrice said:
Re hello,

I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to
export in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :

example :

Dim myStringWriter As System.IO.StringWriter = New
System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing

Error

BC30390: 'System.IO.StringWriter.Protected Overrides Sub
Dispose(disposing As Boolean)' is not accessible in that context. it is
protected..


I can use the Close() method but i m not sure that this last one have
the same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object


Thanks for you help
fabrice
 
C

Cor Ligthert [MVP]

And what does that speed up. The GC runs the most optimal in Idle time.

Setting it to null/nothing means to run an instruction extra in processing
time.

While the reference was direct available before that setting to null,
because without that setting to null/nothing it had already be gone out of
scoop (assuming this is the last instruction in the method as it is
showed)..

cor

Miha Markic said:
Why do you think it is slower? It releases reference to the instance and
thus it is immediately available for GC.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Cor Ligthert said:
Miha, it is normally slower, although it is probably only a clock tick.

I have however seen that C# programmers have more the habit to declare
global than VB.Net programmers do. In that global situation it makes
sense.

Cor

Miha Markic said:
Call Dispose() and then set variable to nothing (the later might just
speed it up a bit or not) - that is the quickest way.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/


Re hello,

I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to
export in .xls file.
To empty memory, I would like to use the propterty dispose on the
object StringWriter.
But i have received an error like this :

example :

Dim myStringWriter As System.IO.StringWriter = New
System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing

Error

BC30390: 'System.IO.StringWriter.Protected Overrides Sub
Dispose(disposing As Boolean)' is not accessible in that context. it is
protected..


I can use the Close() method but i m not sure that this last one have
the same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object


Thanks for you help
fabrice
 
M

Miha Markic [MVP C#]

Cor Ligthert said:
And what does that speed up. The GC runs the most optimal in Idle time.

You don't know when GC kicks in.
Setting it to null/nothing means to run an instruction extra in processing
time.

And that potentially speeds up the garbage collection of instance. I was
under impression that OP was asking how to speed up the collection. Now that
I reread the thread i am not sure anymore.
 

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