HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
tc39
proposal-explicit-resource-management
JavaScript2021–2025
tc39 / proposal-explicit-resource-management

proposal-explicit-resource-management

ECMAScript Explicit Resource Management

29Distinct people
31Mentions
0Explicit recommenders
940GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

ECMAScript Explicit Resource Management

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 9–Nov 16 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/16/2026, 12:56:33 AM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year31 dated mentions

Observed mentions: 2021-12-13 12:59:33 UTC to 2025-09-08 17:13:55 UTC.

0510152021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20212022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 15 mentions; 2 submissions, 13 comments20232024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 10 mentions; 0 submissions, 10 comments2025

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC202
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC101
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC15213
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC303
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC10010

From the project README

An excerpt from the repository, fetched Nov 12, 2026.

Read the project’s introduction
ECMAScript Explicit Resource Management NOTE: This proposal has subsumed the Async Explicit Resource Management proposal. This proposal repository should be used for further discussion of both sync and async of explicit resource management. This proposal intends to address a common pattern in software development regarding the lifetime and management of various resources (memory, I/O, etc.). This pattern generally includes the allocation of a resource and the ability to explicitly release critical resources. For example, ECMAScript Generator Functions and Async Generator Functions expose this pattern through the return method, as a means to explicitly evaluate finally blocks to ensure user-defined cleanup logic is preserved: // sync generators function * g() { const handle = acquireFileHandle(); // critical resource try { ... } finally { handle.release(); // cleanup } } const obj = g(); try { const r = obj.next(); ... } finally { obj.return(); // calls finally blocks in `g` } // async generators async function * g() { const handle = acquireStream(); // critical resource try { ... } finally { await stream.close(); // cleanup } } const obj = g(); try { const r = await obj.next(); ... } finally { await obj.return(); // calls finally blocks in `g` } As such, we propose the adoption of a novel syntax to simplify this common pattern: // sync disposal function * g() { using handle = acquireFileHandle(); // block-scoped critical resource } // cleanup { using obj = g(); // block-scoped declaration const r = obj.next(); } // calls finally blocks in `g` // async disposal async function * g() { using stream = acquireStream(); // block-scoped critical resource ... } // cleanup { await using obj = g(); // block-scoped declaration const r = await obj.next(); } // calls finally blocks in `g` In addition, we propose the addition of two disposable container objects to assist with managing multiple resources: DisposableStack — A stack-based container of disposable resources. AsyncDisposableStack — A stack-based container of asynchronously disposable resources. Status Stage: 3 Champion: Ron Buckton (@rbuckton) Last Presented: March, 2023 (slides, notes #1, notes #2) For more information see the TC39 proposal process. Authors Ron Buckton (@rbuckton) Motivations This proposal is motivated by a number of cases: Inconsistent patterns for resource management: ECMAScript Iterators: iterator.return() WHATWG Stream Readers: reader.releaseLock() NodeJS FileHandles: handle.close() Emscripten C++ objects handles: Module._free(ptr) obj.delete() Module.destroy(obj) Avoiding common footguns when managing resources: const reader = stream.getReader(); ... reader.releaseLock(); // Oops, should have been in a try/finally Scoping resources: const handle = ...; try { ... // ok to use `handle` } finally { handle.close(); } // not ok to use `handle`, but still in scope Avoiding common footguns when managing multiple resources: const a = ...; const b = ...; try { ... } finally { a.close(); // Oops, issue if `b.close()` depends on `a`. b.close(); // Oops, `b` never reached if `a.close()` throws. } Avoiding lengthy code when managing multiple resources correctly: // sync disposal { // block avoids leaking `a` or `b` to outer scope const a = ...; try { const b = ...; try { ... } finally { b.close(); // ensure `b` is closed before `a` in case `b` // depends on `a` } } finally { a.close(); // ensure `a` is closed even if `b.close()` throws } } // both `a` and `b` are out of scope Compared to: // avoids leaking `a` or `b` to outer scope // ensures `b` is disposed before `a` in case `b` depends on `a` // ensures `a` is disposed even if disposing `b` throws using a = ..., b = ...; ... // async sync disposal { // block avoids leaking `a` or `b` to outer scope const a = ...; try { const b = ...; try { ... } finally { await b.close(); // ensure `b` is closed before `a` in case `b` // depends on `a` } } finally { await a.close(); // ensure `a` is closed even if `b.close()` throws } } // both `a` and `b` are out of scope Compared to: // avoids leaking `a` or `b` to outer scope // ensures `b` is disposed before `a` in case `b` depends on `a` // ensures `a` is disposed even if disposing `b` throws await using a = ..., b = ...; ... Non-blocking memory/IO applications: import { ReaderWriterLock } from "..."; const lock = new ReaderWriterLock(); export async function readData() { // wait for outstanding writer and take a read lock using lockHandle = await lock.read(); ... // any number of readers await ...; ... // still in read lock after `await` } // release the read lock export async function writeData(data) { // wait for all readers and take a write lock using lockHandle = await lock.write(); ... // only one writer await ...; ... // still in write lock after `await` } // release the write lock Potential for use with the Fixed Layout Objects Proposal and shared struct: // main.js shared struct class SharedData { ready = false; processed = false; } const worker = new Worker('worker.js'); const m = new Atomics.Mutex(); const cv = new Atomics.ConditionVariable(); const data = new SharedData(); worker.postMessage({ m, cv, data }); // send data to worker { // wait until main can get a lock on 'm' using lck = m.lock(); // mark data for worker data.ready = true; console.log("main is ready"); } // unlocks 'm' // notify potentially waiting worker cv.notifyOne(); { // reacquire lock on 'm' using lck = m.lock(); // release the lock on 'm' and wait for the worker to finish processing cv.wait(m, () => data.processed); } // unlocks 'm' // worker.js onmessage = function (e) { const { m, cv, data } = e.data; { // wait until worker can get a lock on 'm' using lck = m.
Read the full README on GitHub

What Hacker News says

15 sources
In addition to this, is the new (stage 3 even!)explicit resource management proposal[0], supported by TypeScript version >= 5.2[1] Though I agree that async context is better fit for this generally, the ERM should be good for telemetry around objects that have defined lifetime semantics, which is a step in the right direction you can use today [0]: https://github.com/tc39/proposal-explicit-resource-managemen... [1]: https://www.totaltypescript.com/typescript-5-2-new-keyword-u...
In OpenTelemetry in 2023
There's a conversation I had with Ron Buckton, the proposal champion, mainly on this specific issue. [1] Short answer: Yes, Disposable can leak if you forget "using" it. And it will leak if the Disposable is not guarded by advanced GC mechanisms like the FinalizationRegistry. Unlike C# where it's relatively easier to utilize its GC to dispose undisposed resources [2], properly utilizing FinalizationRegistry to do the same thing in JavaScript is not that simple. In response to our conversation, Ron is proposing adding the use of FinalizationRegistry as a best practice note [3], but only for native handles. It's mainly meant for JS engine developers. Most JS developers wrapping anything inside a Disposable would not go through the complexity of integrating with FinalizationRegistry, thus cannot gain the same level of memory-safety, and will
Read the rest
leak if not "using" it. IMO this design will cause a lot of problems, misuses and abuses. But making JS to look more like C# is on Microsoft's agenda so they are probably not going to change anything. [1]: https://github.com/tc39/proposal-explicit-resource-managemen... [2]: https://stackoverflow.com/a/538238/1481095 [3]: https://github.com/tc39/proposal-explicit-resource-managemen...
In TypeScript 5.2's new keyword: 'Using'
I think you’re confusing scope and reachability. Maintaining a reference to an object has nothing to with whether or when it’s disposed in this TC39 language enhancement. Such a system _does_ exist in Object finalizers, but it’s hard to use correctly, especially in a language where it’s very easy to inadvertently retain references via closures. Resource disposal of this type needs to be much more predictable and can’t be left to the whims of the runtime. The docs on finalizers and WeakRefs are full of warnings not to expect them to be predictable or reliable. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... With this new using syntax, resources are disposed of when the object they are tied to goes out of _lexical scope_, which doesn’t need to worry about the runtime or object lifetimes at all. This example from the TC39 pr
Read the rest
oposal makes it pretty clear: function * g() { using handle = acquireFileHandle(); // block-scoped critical resource } // cleanup { using obj = g(); // block-scoped declaration const r = obj.next(); } // calls finally blocks in `g` https://github.com/tc39/proposal-explicit-resource-managemen...
In TypeScript 5.2's new keyword: 'Using'
I'm pretty sure that example won't work and is based on an old version. But assuming a javascript implementation where it works, I don't know what you mean by "language rule". The spec says what "using" means, and it doesn't require any behavior the language doesn't already have. The old spec said "When try using is parsed with an Expression, an implicit block-scoped binding is created for the result of the expression.", and the new one says "When a using declaration is parsed with BindingIdentifier Initializer, the bindings created in the declaration are tracked for disposal at the end of the containing Block or Module". Then the spec has an example implementation written in javascript, with the value being added to a (non-user-accessible) list. https://github.com/tc39/proposal-explicit-resource-managemen... Is that the language rule
Read the rest
you wanted?
In TypeScript 5.2's new keyword: 'Using'
I thought the same and I don't see motivation from it on the TC39 spec page [1] but I do see they have several examples that make use of the feature. It makes me realize I've never really considered the memory implications of doing something like: const { someSmallPart } = getSomeMassiveObject(); I don't really know the lifetime of "massive object". Probably a bad on my part for not knowing if Javascript garbage collection is allowed to notice that the only thing with a reference is `someSmallPart` and could therefore release any other parts of the massive object. If the answer to that is "no" then there is no problem with the above pattern. If the answer is "yes", then things could get complicated. e.g. async function getComplicatedObject() { const db = await db.getConnection( ... ); const f = await file.open( ... );
Read the rest
return { db, f, [Symbol.asyncDispose]: () => { db.close() f.close() } } { await using { f } = getComplicatedObject(); // ... more stuff with awaits where the GC might decide `db` isn't used so it can clean } // I would not expect a null ref error on `db` here when `asyncDispose` is called I mean, you can handle the above even if the GC is allowed to be smart and discard `db` - it just makes it significantly more complicated and requires clever book-keeping. 1. https://github.com/tc39/proposal-explicit-resource-managemen...
In TypeScript 5.2's new keyword: 'Using'

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.