CHAPTER 14 n VB 2008 BEST PRACTICES 339
The Dispose method features a performance boost via the call to GC.SuppressFinalize().
The finalizer of this object merely calls the private Dispose method, and you know that if your
public Dispose method gets called, the finalizer doesn??™t need to do that any longer. So you can
tell the GC not to put the object instance on the finalization queue when the IDisposable.
Dispose method is called. This optimization is more than trivial once you consider the fact
that objects that implement a finalizer live longer than those that don??™t. When the GC goes
through the heap looking for dead objects to collect, it normally compacts the heap and
reclaims their memory. However, if an object has a finalizer, instead of reclaiming the memory
immediately, the GC moves the object over to a finalization list that the separate finalization
thread handles. Once the finalization thread has completed its job on the object, the object is
remarked for deletion, and the GC reclaims the space during a subsequent pass. That??™s why
objects that implement a finalizer live longer than those that don??™t. If your objects eat up lots
of heap memory, or your system creates lots of those objects, finalization starts to become a
huge factor.
Pages:
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553