@tsdotnet/disposable - v2.0.1
    Preparing search index...

    Interface Disposable

    Defines the contract for objects that can be disposed to release resources.

    This interface allows for simple type checking that includes types that don't explicitly declare themselves as implementing this interface but do have a dispose() method. This enables structural typing for disposal operations.

    class DatabaseConnection implements Disposable {
    dispose(): void {
    // Close connection and release resources
    }
    }

    // Can also work with objects that have dispose method without explicit implementation
    const someObject = {
    dispose() {
    console.log('Cleaning up...');
    }
    };
    // someObject is structurally compatible with Disposable
    interface Disposable {
        dispose(): void;
    }

    Implemented by

    Index

    Methods

    Methods

    • Releases all resources used by the object.

      This method should be idempotent - calling it multiple times should have no additional effect after the first call. Implementations should:

      • Release any managed resources
      • Close connections, streams, or handles
      • Unsubscribe from events
      • Clear any references that could prevent garbage collection

      Returns void

      void

      const resource = new SomeDisposableResource();
      try {
      // Use the resource...
      } finally {
      resource.dispose(); // Always dispose when done
      }