Skip to content

Commit

Permalink
Prevent memory leaks in AnimationUpdater (#216)
Browse files Browse the repository at this point in the history
AnimationUpdate removes finished references to prevent memory leaks.
  • Loading branch information
kplindegaard authored Jun 15, 2019
1 parent 8dccdcb commit c68cd69
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 20 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ gauge.set(1250); // set actual value
```

For an interactive demo and a list of all supported options please refer to the [project's homepage](http://bernii.github.com/gauge.js).

## Wrappers

gauge.js can be wrapped to a number of frameworks. Here are some examples:

* **Vue**
* [vgauge](https://github.com/amroessam/vgauge)
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gauge.js",
"version": "1.3.6",
"version": "1.3.7",
"main": [
"dist/gauge.js",
"dist/gauge.min.js",
Expand Down
15 changes: 13 additions & 2 deletions dist/gauge.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class Gauge extends BaseGauge
@value = Math.max(Math.min(value[value.length - 1], @maxValue), @minValue) # TODO: Span maybe??

# Force first .set()
AnimationUpdater.add(@)
AnimationUpdater.run(@forceUpdate)
@forceUpdate = false

Expand Down Expand Up @@ -624,6 +625,7 @@ class BaseDonut extends BaseGauge
else
@minValue = @value

AnimationUpdater.add(@)
AnimationUpdater.run(@forceUpdate)
@forceUpdate = false

Expand Down Expand Up @@ -683,7 +685,8 @@ window.AnimationUpdater =
AnimationUpdater.elements.push(elem)

add: (object) ->
AnimationUpdater.elements.push(object)
if object not in AnimationUpdater.elements
AnimationUpdater.elements.push object

run: (force = false) ->
# 'force' can take three values, for which these paths should be taken
Expand All @@ -693,9 +696,17 @@ window.AnimationUpdater =
isCallback = isFinite(parseFloat(force))
if isCallback or force is true
finished = true
for elem in AnimationUpdater.elements
toRemove = []
for elem, k in AnimationUpdater.elements
if elem.update(force is true)
finished = false
else
toRemove.push k

# Remove finished elements
for k in toRemove by -1
AnimationUpdater.elements.splice k, 1

AnimationUpdater.animId = if finished then null else requestAnimationFrame(AnimationUpdater.run)
else if force is false
if AnimationUpdater.animId is not null
Expand Down
44 changes: 29 additions & 15 deletions dist/gauge.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/gauge.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ <h2>Supported browsers</h2>

<h2>Changes</h2>


<h3 id="v1.3.7">Version 1.3.7 (15.06.2019)</h3>
<p>
<ul>
<li>AnimationUpdater now removes references finished rendering to prevent memory leaks.</li>
</ul>
</p>

<h3 id="v1.3.6">Version 1.3.6 (28.11.2017)</h3>
<p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gaugeJS",
"version": "1.3.6",
"version": "1.3.7",
"description": "100% native and cool looking animated JavaScript/CoffeeScript gauge",
"main": "dist/gauge.js",
"repository": {
Expand Down

0 comments on commit c68cd69

Please sign in to comment.