May 2004
Intermediate to advanced
888 pages
22h 31m
English
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 ...
Read now
Unlock full access