Home All Groups Group Topic Archive Search About

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

Author
14 Nov 2006 1:32 PM
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

>> 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

Author
15 Nov 2006 5:06 AM
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

Show quote
"fabrice" <emouc***@test.com> schreef in bericht
news:%23C9taF$BHHA.4256@TK2MSFTNGP04.phx.gbl...
>
> 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
>
>
Author
15 Nov 2006 8:56 AM
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.

--
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/

Show quote
"fabrice" <emouc***@test.com> wrote in message
news:%23C9taF$BHHA.4256@TK2MSFTNGP04.phx.gbl...
>
> 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
>
>
Author
15 Nov 2006 6:43 PM
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

Show quote
"Miha Markic [MVP C#]" <miha at rthand com> schreef in bericht
news:627979F7-B366-48D2-9439-E4D533FE58AA@microsoft.com...
> 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" <emouc***@test.com> wrote in message
> news:%23C9taF$BHHA.4256@TK2MSFTNGP04.phx.gbl...
>>
>> 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
>>
>>
>
Author
15 Nov 2006 7:24 PM
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/

Show quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:O5vHgWOCHHA.4680@TK2MSFTNGP04.phx.gbl...
> 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 [MVP C#]" <miha at rthand com> schreef in bericht
> news:627979F7-B366-48D2-9439-E4D533FE58AA@microsoft.com...
>> 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" <emouc***@test.com> wrote in message
>> news:%23C9taF$BHHA.4256@TK2MSFTNGP04.phx.gbl...
>>>
>>> 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
>>>
>>>
>>
>
>
Author
15 Nov 2006 7:59 PM
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

Show quote
"Miha Markic [MVP C#]" <miha at rthand com> schreef in bericht
news:94B0B672-0EB2-45C6-AA9E-713A63B3DAA5@microsoft.com...
> 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 [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:O5vHgWOCHHA.4680@TK2MSFTNGP04.phx.gbl...
>> 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 [MVP C#]" <miha at rthand com> schreef in bericht
>> news:627979F7-B366-48D2-9439-E4D533FE58AA@microsoft.com...
>>> 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" <emouc***@test.com> wrote in message
>>> news:%23C9taF$BHHA.4256@TK2MSFTNGP04.phx.gbl...
>>>>
>>>> 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
>>>>
>>>>
>>>
>>
>>
>
Author
15 Nov 2006 10:08 PM
Miha Markic [MVP C#]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uSJ%23RBPCHHA.3600@TK2MSFTNGP06.phx.gbl...
> 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.

--
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/

AddThis Social Bookmark Button