UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

41 lines 1.49 kB
import { lifecycleStack } from "./lifecycle-stack.js"; import { ReferenceCountedNode } from "../../lifecycle/reference-counted-node.js"; import { DebugSharedPointerChecks } from "../util/debug-shared-pointer-checks.js"; /** * @public * The recommended lifecycle strategy. This strategy only adds debug checks for leaking objects; you must unlink * objects from their owners once they are finished with them. */ export class ReferenceCountedStrategy { createNode(owner) { owner !== null && owner !== void 0 ? owner : (owner = lifecycleStack.getTop()); const newNode = new ReferenceCountedNode(); owner.getLinked().link(newNode); newNode.onReleased(); return newNode; } /** * @internal */ createRootNode() { return new ReferenceCountedNode(); } onSharedPointerCreated(sharedPtr, metadata, protectedView) { if (_BUILD.DEBUG) { DebugSharedPointerChecks.registerWithCleanup(this.wrapper, sharedPtr, metadata, protectedView); this.wrapper.debugUtils.sharedObjectLifeCycleChecks.registerFinalizationCheck(sharedPtr, metadata); } } onManagedObjectCreated(object) { if (_BUILD.DEBUG) { this.wrapper.debugUtils.sharedObjectLifeCycleChecks.registerFinalizationCheck(object, null); } } /** * @internal */ setWrapper(wrapper) { this.wrapper = wrapper; } } //# sourceMappingURL=reference-counted-strategy.js.map