From: Ulrich-Matthias Schäfer Date: Sat, 2 Sep 2023 19:44:19 +0000 (+0200) Subject: add terminate method to timeline so memory can be freed X-Git-Tag: 3.2.1~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=29b2bd7f811584380b35434d5bf29913ffe93459;p=svg.js.git add terminate method to timeline so memory can be freed --- 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({