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
resourcefrom 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
callbackwithin an automatic resource management scope, automatically detaching and returning the resulting ScopedResource to the parent scope (if any). -
scope<
R> (R callback()) → R -
Executes
callbackwithin an automatic resource management scope. -
track(
ScopedResource resource) → void -
Registers
resourcewith the active ResourceScope in Zone.current, if any. -
unmanaged<
R> (R callback()) → R -
Executes
callbackwithin an unmanaged context, preventing any created ScopedResources from being registered in or disposed of by active scopes. -
untrack(
ScopedResource resource) → void -
Removes
resourcefrom the active ResourceScope in Zone.current, if any.
Constants
- trackAllocations → const bool
-
Whether allocation leak tracking is enabled via
--dart-define=TRACK_RESOURCE_ALLOCATIONS=trueor--dart-define=TRACK_NDARRAY_ALLOCATIONS=true.