User Manual

Dispose Tracker

The dispose tracker is a powerful tool for tracking memory problems pertaining to disposable types. Any type that implements IDisposable signals that all its instances should be disposed as soon as they are not needed anymore. Often these types wrap unmanaged resources, such as file handles, database connections, bitmaps, etc. The types may also be disposable because they contain references to other disposable instances, or they simply need to know when they are not needed anymore.

By using finalizers, disposable classes wrapping unmanaged resources can usually handle the clean-up of its resources. One problem is that there is no guarantee when the finalizer will be called, it may very well take a long time. For scarce resources such as file handles and database connections this can prove to be a very significant problem. There is also a cost involved with using finalizers. For more information look at the articles provided under “Details on the Garbage Collector”.

Another problem is that the garbage collector has no notion of the cost of an unmanaged resource. For instance, a bitmap may use several megabytes of memory, but the garbage collector only sees the memory used by the instance keeping a handle to the bitmap.

Additionally, the documentation suggests that, if Dispose is not called properly, the finalizer will eventually clean up any unmanaged resources and the instance will be garbage collected. However, this is not always the case. Instances of some classes in the framework will never be finalized and garbage collected unless they are disposed.  

The abovementioned problems suggest that you should always call Dispose on instances of disposable types, and the dispose tracker helps you to make sure that all instances are disposed.

The dispose tracker is enabled by default unless low-impact profiling is active. The dispose tracker does not use any additional memory, and it has very low performance overhead, so it is recommended that is always be enabled.

To view the information collected by the dispose tracker, the Dispose info field set should be used. When this field set is selected, some of the information presented in the different profiler views is replaced by dispose information. For more information about which information is replaced, see the documentation about Field Sets.

The dispose information includes:

      Disposed instances

The numbers presented for disposed instances represent the number of instances that have been disposed, but not yet garbage collected. For more information, see Disposed Instances.

      Undisposed instances

The numbers presented for undisposed instances represent the number of instances that have been garbage collected without being properly disposed. For more information, see Undisposed instances.

More:

Disposed Instances

Undisposed instances