Last week's .NET Rocks
show with Jeff Richter was a great one. I always find it interesting to
hear about the types of things that went (and are still going) into the
design/implementation of the CLR. During the show, Jeff mentioned a
couple of tips for helping the garbage collector be more efficient.
Keep object lifetimes as short as possible.
I think this is essentially the same advice that's usually given for
dealing with unmanaged resources (file streams, database connections,
etc) -- get it late, release it early. It also tells me that I need to
do some more reading up on WHY this is the case in the GC. My
assumption is that it has to do with objects getting promoted through
various levels of the GC and how often it runs through to free up
memory. Definitely need to get a good book on the CLR guts. Suggestions?
Keep the call stack as short as possible.
Again, I'm not sure why this is and plan to read up on it in more
detail. But it does seem at odds with the common design/implementation
goals of loose coupling and short methods. Usually, you want lots of
small, cohesive objects that work together to form a larger component.
Within those objects, you want relatively short methods that can use
one another to perform an operation (do one thing, do it well, and do
only that). The side effect of that approach is that the call stack
gets fairly deep in short order. It may be that 95% of me experience in
.NET has been in the Winforms world -- wherein applications
typically (and as was mentioned on the show) are going to have
deeper call stacks than ASP.NET applications.
Anyway, interesting stuff... now off to find some good under-the-hood GC resources.
