dispose Function

Convenience function for disposing of a disposable object that may be undefined. This is primarily used to simplify implementations of dispose. As a simple example:

 class Disposable implements IDisposable {
   public member1?: DisposableType1;
   public member2?: DisposableType2;

   public dispose() {
     this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.
     this.member2 = dispose(this.member2); // Likewise for member2.
   }
 }

dispose(disposable?: IDisposable): undefined

@returns undefined

Parameter Type Description
disposable IDisposable The object to be disposed of.

Returns - undefined

undefined

Defined in

Last Updated: 17 December, 2024