Limited supportVery useful when your code opens handles, streams, or other resources that must be released reliably.

Overview

Explicit resource management adds a structured way to clean up disposable resources with using declarations. It makes ownership and teardown more visible in code.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
134
134
141
134
AsyncDisposableStack.@@asyncDispose
134
134
141
134

The AsyncDisposableStack() constructor creates AsyncDisposableStack objects.

134
134
141
134

The adopt() method of AsyncDisposableStack instances registers a value that doesn't implement the async disposable protocol to the stack by providing a custom disposer function.

134
134
141
134

The defer() method of AsyncDisposableStack instances takes a callback function to be called and awaited when the stack is disposed.

134
134
141
134

The disposeAsync() method of AsyncDisposableStack instances disposes this stack by calling all disposers registered to it in reverse order of registration, awaiting for each one's completion before calling the next one. If the stack is already disposed, this method does nothing.

134
134
141
134

The disposed accessor property of AsyncDisposableStack instances returns a boolean indicating whether or not this AsyncDisposableStack has been disposed or moved by doing any of the following:

134
134
141
134

The move() method of AsyncDisposableStack instances creates a new AsyncDisposableStack instance that contains the same disposers as this stack, and then marks this stack as disposed, without calling any disposers.

134
134
141
134

The use() method of AsyncDisposableStack instances registers a value that implements the async disposable protocol to the stack.

134
134
141
134
AsyncIterator.@@asyncDispose
134
134
141
134
Other

The DisposableStack object represents a stack of disposers to run when the stack itself is disposed. Disposer functions are executed in reverse order of registration, with strong error handling guarantees. Calling its move() method will transfer responsibility for calling the current registered disposers to a new DisposableStack and prevent registering any…

134
134
141
134
Built-in object
DisposableStack.@@dispose
134
134
141
134

The DisposableStack() constructor creates DisposableStack objects.

134
134
141
134

The adopt() method of DisposableStack instances registers a value that doesn't implement the disposable protocol to the stack by providing a custom disposer function.

134
134
141
134

The defer() method of DisposableStack instances takes a callback function to be called when the stack is disposed.

134
134
141
134

The dispose() method of DisposableStack instances disposes this stack by calling all disposers registered to it in reverse order of registration. If the stack is already disposed, this method does nothing.

134
134
141
134

The disposed accessor property of DisposableStack instances returns a boolean indicating whether or not this DisposableStack has been disposed or moved by doing any of the following:

134
134
141
134

The move() method of DisposableStack instances creates a new DisposableStack instance that contains the same disposers as this stack, and then marks this stack as disposed, without calling any disposers.

134
134
141
134

The use() method of DisposableStack instances registers a value that implements the disposable protocol to the stack.

134
134
141
134
Iterator.@@dispose
134
134
141
134
Other

The SuppressedError object represents an error generated while handing another error. It is generated during resource disposal using Statements/using or Statements/await_using.

134
134
141
134
Built-in object

The SuppressedError() constructor creates SuppressedError objects.

134
134
141
134

The error data property of a SuppressedError instance contains a reference to the error that results in the suppression.

134
134
141
134

The suppressed data property of a SuppressedError instance contains a reference to the original error that got suppressed because a new error was generated while handling it.

134
134
141
134

The Symbol.asyncDispose static data property represents the well-known symbol Symbol.asyncDispose. The Statements/await_using declaration looks up this symbol on the variable initializer for the method to call when the variable goes out of scope.

127
127
141
127

The Symbol.dispose static data property represents the well-known symbol Symbol.dispose. The Statements/using declaration looks up this symbol on the variable initializer for the method to call when the variable goes out of scope.

125
125
141
125
Other

The await using declaration declares block-scoped local variables that are asynchronously disposed. Like Statements/const, variables declared with await using must be initialized and cannot be reassigned. The variable's value must be either null, undefined, or an object with a…

134
134
141
134

The using declaration declares block-scoped local variables that are synchronously disposed. Like Statements/const, variables declared with using must be initialized and cannot be reassigned. The variable's value must be either null, undefined, or an object with a [[Symbol.dispose]()](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/dispose)…

134
134
141
134
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
// Automatically release resources using the `using` statement
{
  using file = openFile('data.txt');
  // Use file
} // `file[Symbol.dispose]()` is automatically called when the scope ends

// Asynchronous version
await using db = connectDB();

Use cases

  • Deterministic cleanup

    Release file handles, subscriptions, or temporary resources automatically at the end of a scope.

  • Safer failure paths

    Avoid leaking resources when code exits early due to thrown errors or conditional returns.

Cautions

  • The pattern is most useful when resources truly need explicit teardown; avoid introducing ceremony where no resource lifecycle exists.
  • Team understanding matters because disposal hooks and scope-based cleanup change how ownership is read.

Accessibility

  • No direct accessibility effect, but reliable cleanup reduces unstable behavior in long-running apps and tools.
  • Resource release should not silently remove user data or state without a clear UI contract.

Powered by web-features