Class JCOBridgeDisposeAsyncScope
Opens a batch scope for deferred JVM global reference disposal, safe for use in async/await contexts. Disposal of JVM objects within this scope is batched and flushed in a single P/Invoke call when the scope exits, reducing crossing overhead. The scope state flows automatically across await continuations.
public sealed class JCOBridgeDisposeAsyncScope : IDisposable
- Inheritance
-
JCOBridgeDisposeAsyncScope
- Implements
- Inherited Members
- Extension Methods
Remarks
Use this scope when working with async code or when continuations may resume on a different thread. For synchronous hot paths prefer JCOBridgeDisposeFastScope.
await using var scope = new JCOBridgeDisposeAsyncScope();
await foreach (var item in asyncCollection)
{
using (item) { /* item disposal is batched */ }
}
Constructors
JCOBridgeDisposeAsyncScope(int)
Initializes a new batch dispose scope for async contexts. Disposal of JVM objects within this scope is batched and flushed in a single native call when the scope exits. The scope state flows automatically across await continuations.
public JCOBridgeDisposeAsyncScope(int maxPerBatch = 64)
Parameters
maxPerBatchintMaximum number of JVM references to queue before an automatic flush is triggered. Defaults to 64.
Examples
await using var scope = new JCOBridgeDisposeAsyncScope();
await foreach (var item in asyncCollection)
{
using (item) { /* item disposal is batched */ }
}
Methods
Dispose()
Releases the batch scope, flushing any queued JVM global reference releases in a single native call. Suppresses finalization after disposal.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
~JCOBridgeDisposeAsyncScope()
Finalizer
protected ~JCOBridgeDisposeAsyncScope()