From 29b2bd7f811584380b35434d5bf29913ffe93459 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ulrich-Matthias=20Sch=C3=A4fer?= Date: Sat, 2 Sep 2023 21:44:19 +0200 Subject: [PATCH] add terminate method to timeline so memory can be freed --- src/animation/Timeline.js | 47 ++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/animation/Timeline.js b/src/animation/Timeline.js index 39e0f1a..2f6f5d3 100644 --- a/src/animation/Timeline.js +++ b/src/animation/Timeline.js @@ -27,26 +27,8 @@ export default class Timeline extends EventTarget { this._timeSource = timeSource - // Store the timing variables - this._startTime = 0 - this._speed = 1.0 - - // Determines how long a runner is hold in memory. Can be a dt or true/false - this._persist = 0 - - // Keep track of the running animations and their starting parameters - this._nextFrame = null - this._paused = true - this._runners = [] - this._runnerIds = [] - this._lastRunnerId = -1 - this._time = 0 - this._lastSourceTime = 0 - this._lastStepTime = 0 - - // Make sure that step is always called in class context - this._step = this._stepFn.bind(this, false) - this._stepImmediate = this._stepFn.bind(this, true) + // terminate resets all variables to their initial state + this.terminate() } active() { @@ -326,6 +308,31 @@ export default class Timeline extends EventTarget { return this } + + terminate() { + // cleanup memory + + // Store the timing variables + this._startTime = 0 + this._speed = 1.0 + + // Determines how long a runner is hold in memory. Can be a dt or true/false + this._persist = 0 + + // Keep track of the running animations and their starting parameters + this._nextFrame = null + this._paused = true + this._runners = [] + this._runnerIds = [] + this._lastRunnerId = -1 + this._time = 0 + this._lastSourceTime = 0 + this._lastStepTime = 0 + + // Make sure that step is always called in class context + this._step = this._stepFn.bind(this, false) + this._stepImmediate = this._stepFn.bind(this, true) + } } registerMethods({ -- 2.39.5