Re: Calling destructor

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Joe Mayo [C# MVP] (jmayo_at_nospamAtCSharpDashStation.com)
Date: 03/17/04


Date: Wed, 17 Mar 2004 08:10:06 -0700


"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1ac2201c9589515998a402@msnews.microsoft.com...
> Joe Mayo [C# MVP] <jmayo@nospamAtCSharpDashStation.com> wrote:
> > Something you can do, that will help, is to set references to null for
those
> > objects you are no longer using. That way, you give the GC a chance to
> > clean them up for you. As long as you hold references to an object, the
GC
> > can't clean them up.
>
> It's rarely a good idea to do so, however. Most of the time, I find
> that any time I know a variable is no longer needed, either it's a
> local variable and the JIT would be able to work out that it's no
> longer needed, or the enclosing object is *also* no longer needed, so
> the variable isn't preventing garbage collection anyway.
>
> I can't remember the last time I found it a good idea to set a variable
> to null explicitly for the purpose of garbage collection.

OP described how he had a large graph of objects and needed the ability to
clear <something> manually. Because <something> is unclear and the specific
data structure implementation and architecture is unknown, making
assumptions about proper design may not be accurate.

For example, what if the graph data structure persists for the life of the
application, yet he needs the ability to add/remove nodes on a continuous
basis. In such a scenario, setting a reference to the object to null
effectively removes it from the graph and makes it available for GC
(providing no other references exist).

In another setting, if he wanted to release the entire graph or the object
containing the graph, then the scenario you describe could be more
appropriate.

I'm not particularly inclined to dismiss someone else's design or ideas just
because I haven't seen it before.

Joe

-- 
http://www.csharp-station.com


Relevant Pages

  • Re: 120 day moving graph window
    ... been able to associate this to a scroll bar. ... figure out how to get these changing cell references into the graphs ... Google it but basically you draw the graph with any range you like. ... function using absolute references which gives the range you want. ...
    (microsoft.public.excel.charting)
  • Re: maximal 3-colorable subset
    ... johank wrote: ... a optimisation variant of graph coloring that fixes the number ... # difficulties finding references that address such problems. ...
    (comp.theory)
  • Re: Checking for null parameter
    ... like to store your document locally until the remote document storage is back? ... In this scenario, an external resource was not available, and deep down threw ... } catch (ConnectionException e) { ... But I will not check for null references in every method or contructor ...
    (comp.lang.java.programmer)