all groups > dotnet general > june 2004 >
You're in the

dotnet general

group:

Correct way of using Dispose


Re: Correct way of using Dispose Marina
6/22/2004 10:43:43 AM
dotnet general: You do not need to set anything to Nothing. You only needed to do that in
VB6.

[quoted text, click to view]

Re: Correct way of using Dispose Jon Skeet [C# MVP]
6/22/2004 3:42:34 PM
[quoted text, click to view]

Assuming it's a local variable which isn't used again, or an instance
variable in an instance which is about to become eligible for garbage
collection, there's no need to do this.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Correct way of using Dispose kjon
6/22/2004 10:38:25 PM
I always dispose any object with the following:
If not (obj1 is nothing) then obj1.dispose

Now I wonder if that is the correct way of disposing an object? Should I use
obj1 = Nothing after the dispose? Pls advice. Thanks.

Re: Correct way of using Dispose jimi_with_an_i NO[at]SPAM yahoo-dot-ca.no-spam.invalid
6/23/2004 10:02:37 AM
[quoted text, click to view]
You do not need to set anything to Nothing. You only needed to do
that in VB6.

Actually, in wasn't even required in VB6 - it was required I think
only as late as VB4 due to a bug in VB4, but was endlessly
perpetuated by well-meaning developers after that.


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
Re: Correct way of using Dispose AlexS
6/23/2004 10:55:01 AM
This is standard misconception and recipe for future problems. GC is able to
cope only with limited number of allocations per time unit and is not ideal,
read has limitations. If it is not able to detect that reference could be
freed, related resource might survive through many GC cycles.
See
http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp
for additional details.

HTH
Alex

[quoted text, click to view]

Re: Correct way of using Dispose Cor Ligthert
6/23/2004 11:24:47 AM
In addition to Marina,

I think see means objects you can set properties to Nothing by instance a
datasource or a binding.
(Or did I misunderstood it Marina?)


Cor

[quoted text, click to view]

Re: Correct way of using Dispose AlexS
6/23/2004 1:52:39 PM
[quoted text, click to view]

Like I said it depends on application. Local variables allocated on stack -
I agree, there is not much sense in nulling them. However, I would suggest
to check the topic "Set Unneeded Member Variables to Null Before Making
Long-Running Calls" in the link I recommended. It explains some of caveats
with local variables. Problem is that any heap allocation under certain
conditions can survive GC cycles for very long periods of time. Which
finally can cause troubles. That's why I suggest not to adopt generic rules,
which might work or not. Definition of long call is very application
specific.
HTH

Alex

Re: Correct way of using Dispose Jon Skeet [C# MVP]
6/23/2004 4:47:35 PM
[quoted text, click to view]

In the vast majority of cases, however, it does *not* help to set
variables to null/Nothing.

[quoted text, click to view]

Note that that specifically says not to bother with it for local
variables.

In my experience, it's very rare to have members which are unneeded
until the rest of the object becomes eligible for garbage collection.
In fact, I can't remember the last time it made sense to set something
to null just for the sake of garbage collection.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Re: Correct way of using Dispose Cor Ligthert
6/23/2004 5:32:06 PM
Hi Alex,

What do you want to say with that?

And please send it next time as an answer for Marina, now see maybe does not
see it because you answered a message from me.

I know that document.

Cor

[quoted text, click to view]

Re: Correct way of using Dispose Jon Skeet [C# MVP]
6/23/2004 7:42:35 PM
[quoted text, click to view]

Yes, but I would be wary of variables which can be set to null like
this - usually it indicates something being a member variable which
should have been a local variable in the first place.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button