
Signature
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
> //allocate
> thing X=new thing();
[quoted text clipped - 5 lines]
> In managed code, memory is deallocated by the garbage collector when it's
> no longer needed.
If the OP really wants to talk about *memory* then the call to Dispose does
nothing about memory but does allow the object to clear up non-memory
resources.
The setting of x to null is unnecessary and doesn;t do anything at all as x
is a local variable. If x was static then setting to null would be vital in
allowing the object to be cleaned up. If x were a member variable then
setting it to null *might* be worth it

Signature
Regards
Richard Blewett
DevelopMentor
http://www.dotnetconsult.co.uk/weblog2
Jon - 06 Mar 2008 11:49 GMT
"but does allow the object to clear up non-memory resources"
Which may themselves use memory.
> //allocate
> thing X=new thing();
[quoted text clipped - 5 lines]
> In managed code, memory is deallocated by the garbage collector when it's
> no longer needed.
If the OP really wants to talk about *memory* then the call to Dispose does
nothing about memory but does allow the object to clear up non-memory
resources.
The setting of x to null is unnecessary and doesn;t do anything at all as x
is a local variable. If x was static then setting to null would be vital in
allowing the object to be cleaned up. If x were a member variable then
setting it to null *might* be worth it

Signature
Regards
Richard Blewett
DevelopMentor
http://www.dotnetconsult.co.uk/weblog2
Bob Powell [MVP] - 06 Mar 2008 22:08 GMT
>> thing X=new thing();
x
is a local variable.
Do you see a class declaration in there??

Signature
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
>> //allocate
>> thing X=new thing();
[quoted text clipped - 14 lines]
> in allowing the object to be cleaned up. If x were a member variable then
> setting it to null *might* be worth it
Jon Skeet [C# MVP] - 06 Mar 2008 23:20 GMT
> >> thing X=new thing();
> x
> is a local variable.
>
> Do you see a class declaration in there??
No, but then I didn't see a method declaration either.
If X is really meant to be a local variable, then setting it to null is
almost certainly a bad idea - and if Thing implements IDisposable,
then a using statement would almost certainly be more appropriate than
manually calling Dispose.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk