Code Around C#'s Using Statement to Release Unmanaged Resources

Download Now Free registration required

Executive Summary

Suppose the developer obtained unmanaged resources in a class constructor during object construction and the created object was provided to a using statement. However, the resources were not released at the end of the using statement's usage block. Instead, they were released during garbage collection, as the developer may expect. Sorting through the application's IL code with the DbgCLR debugger, the developer may find that an exception was thrown from the class constructor. So, not only was the object not fully constructed, the Dispose() method was not called when the unmanaged resources were expected to be released. Thus, they were not released and contributed to the resource consumption.

  • Format: HTML
  • Size: 0 KB