endScope(result) {
        const tensorsToTrackInParent = (0, _tensorUtil.getTensorsInContainer)(result);
        const tensorsToTrackInParentSet = new Set(tensorsToTrackInParent.map((t)=>t.id));
        // Dispose the arrays tracked in this scope.
        for(let i = 0; i < this.state.activeScope.track.length; i++){
            const tensor = this.state.activeScope.track[i];
            if (!tensor.kept && !tensorsToTrackInParentSet.has(tensor.id)) tensor.dispose();
        }
        const oldScope = this.state.scopeStack.pop();
        this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1];
        // Track the current result in the parent scope.
        tensorsToTrackInParent.forEach((tensor)=>{
            // Only track the tensor if was allocated in the inner scope and is not
            // globally kept.
            if (!tensor.kept && tensor.scopeId === oldScope.id) this.track(tensor);
        });
    }
End a scope. Use this with startScope() to achieve the same functionality
as scope() without the need for a function closure.