ResourceScope class final

Automatic zone-based scoped resource manager for ScopedResource instances.

Use ResourceScope.scope to execute code blocks where any created ScopedResource is automatically disposed when the scope finishes.

Use ResourceScope.returning to automatically promote a returned ScopedResource to the outer parent scope while disposing all intermediate allocations.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

trackedAllocations → List<ScopedResource>
Returns a list of currently active root (undisposed) ScopedResources when trackAllocations is enabled.
no setter

Static Methods

checkNoLeaks() → bool
Checks that all tracked ScopedResources have been disposed. Throws a StateError if any undisposed resources remain.
clearTrackedAllocations() → void
Clears the list of tracked allocations.
promoteToParent(ScopedResource resource) → void
Promotes resource from the current active scope to its parent outer scope, or throws a StateError if there is no active scope.
returning<T extends ScopedResource>(T callback()) → T
Executes callback within an automatic resource management scope, automatically detaching and returning the resulting ScopedResource to the parent scope (if any).
scope<R>(R callback()) → R
Executes callback within an automatic resource management scope.
track(ScopedResource resource) → void
Registers resource with the active ResourceScope in Zone.current, if any.
unmanaged<R>(R callback()) → R
Executes callback within an unmanaged context, preventing any created ScopedResources from being registered in or disposed of by active scopes.
untrack(ScopedResource resource) → void
Removes resource from the active ResourceScope in Zone.current, if any.

Constants

trackAllocations → const bool
Whether allocation leak tracking is enabled via --dart-define=TRACK_RESOURCE_ALLOCATIONS=true or --dart-define=TRACK_NDARRAY_ALLOCATIONS=true.