-
Notifications
You must be signed in to change notification settings - Fork 1
StdLib Disposable WeakRef
Resource management and weak reference utilities.
Manages a stack of disposable resources for the using declaration.
Implementation Status: 100% Complete (marked FLAKY)
using stack = new DisposableStack();
stack.use(resource); // Auto-disposed when block exits| Method | Status | Description |
|---|---|---|
new DisposableStack() |
Implemented | Creates empty stack |
| Method | Status | Description |
|---|---|---|
use(value) |
Implemented | Adds disposable, returns value |
adopt(value, onDispose) |
Implemented | Adds value with custom dispose |
defer(onDispose) |
Implemented | Adds cleanup callback |
move() |
Implemented | Transfers resources to new stack |
dispose() |
Implemented | Disposes all resources |
[Symbol.dispose]() |
Implemented | Alias for dispose() |
disposed (getter) |
Implemented | Is stack disposed |
{
using stack = new DisposableStack();
const file = stack.use(openFile("data.txt"));
stack.defer(() => console.log("cleanup"));
// file disposed, "cleanup" logged when block exits
}Async version of DisposableStack for await using.
Implementation Status: 100% Complete (marked FLAKY)
await using stack = new AsyncDisposableStack();
stack.use(asyncResource);| Method | Status | Description |
|---|---|---|
new AsyncDisposableStack() |
Implemented | Creates empty stack |
| Method | Status | Description |
|---|---|---|
use(value) |
Implemented | Adds async disposable |
adopt(value, onDispose) |
Implemented | Adds with custom async dispose |
defer(onDispose) |
Implemented | Adds async cleanup callback |
move() |
Implemented | Transfers to new stack |
disposeAsync() |
Implemented | Async dispose all resources |
[Symbol.asyncDispose]() |
Implemented | Alias for disposeAsync() |
disposed (getter) |
Implemented | Is stack disposed |
Allows cleanup callbacks when objects are garbage collected.
Implementation Status: 0% (Stubs Only)
| Method | Status | Description |
|---|---|---|
new FinalizationRegistry(callback) |
Stub | Creates stub instance |
| Method | Status | Description |
|---|---|---|
register(target, heldValue, token) |
Not Implemented | Throws NotImplementedException |
unregister(token) |
Not Implemented | Throws NotImplementedException |
cleanupSome(callback) |
Missing | Not defined |
Note: FinalizationRegistry requires integration with the .NET garbage collector which is not implemented.
Holds a weak reference to an object.
Implementation Status: Simplified (Not True Weak)
| Method | Status | Description |
|---|---|---|
new WeakRef(target) |
Implemented | Creates "weak" reference |
| Method | Status | Description |
|---|---|---|
deref() |
Implemented | Returns target or undefined |
The current implementation stores the target as a regular property, not a true weak reference:
// Current implementation (simplified)
instance.SetProperty("_target", target); // Strong reference!This means:
- Objects held by WeakRef will never be garbage collected
-
deref()will never returnundefineddue to GC - WeakRef behaves like a regular object wrapper
For true weak reference semantics, use WeakMap/WeakSet which use ConditionalWeakTable.
Sync disposal uses [Symbol.dispose]:
const resource = {
[Symbol.dispose]() {
console.log("disposed");
}
};
{
using r = resource;
} // "disposed" loggedAsync disposal uses [Symbol.asyncDispose]:
const asyncResource = {
async [Symbol.asyncDispose]() {
await cleanup();
console.log("async disposed");
}
};
{
await using r = asyncResource;
} // "async disposed" logged| File | Purpose |
|---|---|
StdLib/DisposableStack/DisposableStackConstructor.cs |
Constructor |
StdLib/DisposableStack/DisposableStackPrototype.cs |
Prototype methods |
StdLib/AsyncDisposableStack/AsyncDisposableStackConstructor.cs |
Async constructor |
StdLib/AsyncDisposableStack/AsyncDisposableStackPrototype.cs |
Async methods |
StdLib/FinalizationRegistry/FinalizationRegistryConstructor.cs |
Stub |
StdLib/FinalizationRegistry/FinalizationRegistryPrototype.cs |
Stubs |
StdLib/WeakRef/WeakRefConstructor.cs |
Constructor |
StdLib/WeakRef/WeakRefPrototype.cs |
deref() |
JsTypes/JsDisposableStackBase.cs |
Shared base class |
- WeakCollections - WeakMap/WeakSet (true weak references)
- Symbol-System - Symbol.dispose and Symbol.asyncDispose