The dispose pattern gives developers an explicit mechanism to release unmanaged resources immediately rather than relying on a GC cycle. This is accomplished by implementing the IDisposable interface.
Consider the TCriticalSection class from the previous section. The following is its reworked definition that implements IDisposable:
TCriticalSection = class(TObject, IDisposable) private FSection: TRTLCriticalSection; FCSValid: Boolean; strict protected procedure Finalize; override; public constructor Create; procedure Dispose; end;
You should notice that the object now implements the IDisposable interface and its Dispose() procedure. Also, an FCSValid Boolean field will be initialized to False ...