Re: "using" vs "= null" and object lifetime

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 02/17/05


Date: Thu, 17 Feb 2005 18:02:09 -0000

Nicholas Paldino [.NET/C# MVP] <mvp@spam.guard.caspershouse.com> wrote:
> > void SomeFunc()
> > {
> > MyClass c = new MyClass();
> > c.CallSomeOtherFunc();
> > c = null;
> > }
>
> This depends on how it is compiled. If you are compiling in debug mode,
> then yes, it will make it GC faster (although how much faster is
> questionable since c would have been released very quickly afterwards, due
> to exiting the method). The reason for this is that code compiled in debug
> mode will not have references released when they are no longer used.

Are you sure it's a case of how it's compiled? I was under the
impression that it was how it was being *run* - which would make sense,
as if you're not running in the debugger, you don't need to know the
value of c after the last use even if the debug symbols are present.

When I get the chance I may test this in each configuration just to see
what happens...

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Conditional compilation
    ... Herman Gomez wrote: ... Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time: ... That way I can include/exclude easily all debugging code in the final compiled code. ... The only solution I've found is having this kind of code in every debug code block: ...
    (php.general)
  • Re: Productivity in programming of C++ programmers
    ... >> debugger will hit the breakpoint. ... I think the reason is that I compiled my library parse.lib in debug mode ... In the past, I found that creating a release parse.lib file, then compiling ...
    (comp.lang.cpp)
  • Re: Execution time debug vs. release
    ... Note that VS is doing more and more runtime checks in debug mode, ... You could check this out by compiling just one of your files in VS7 and VS8 with the ... speed with Task Manager showing 0% CPU time. ...
    (microsoft.public.vc.mfc)
  • Re: MFC program does not start
    ... Are you compiling a Debug version of the code? ... sort of error ASSERT() message. ... If it is not reaching the InitInstance() ... Debug mode you will have more of a chance of seeing something in the Output ...
    (microsoft.public.vc.mfc)
  • Re: conditional break on error?
    ... FuncA calls FuncB calls FuncC ... Look up the Debug object and specifically its Assert method. ... it's BEST to remove any Debug.Assert lines of code prior to compiling. ... There are 3 options for watches, one of which is to break when the watch expression evaluates to True. ...
    (microsoft.public.vb.general.discussion)