Skip to content

Commit 135a84a

Browse files
committed
Allow garbage collection of inherited transition.
When creating a new transition derived from an existing transition, the new transition’s parameters (reference time, delay, duration and easing) are inherited. However, we were inadvertantly also capturing a reference to the old transition lock, including any tweens and listeners. Even though this object wasn’t used by the transition after creation, it’s likely that the garbage collector wasn’t smart enough to free the old lock. We now set the lock to null explicitly so as to allow garbage collection and avoid a memory leak with chained transitions. Related d3#2110. Also, create a new object when using transition.transition rather than using Object.create. It’s slightly more code, but it’s simpler.
1 parent d659844 commit 135a84a

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

d3.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8576,9 +8576,13 @@
85768576
subgroups.push(subgroup = []);
85778577
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
85788578
if (node = group[i]) {
8579-
transition = Object.create(node.__transition__[id0]);
8580-
transition.delay += transition.duration;
8581-
d3_transitionNode(node, i, id1, transition);
8579+
transition = node.__transition__[id0];
8580+
d3_transitionNode(node, i, id1, {
8581+
time: transition.time,
8582+
ease: transition.ease,
8583+
delay: transition.delay + transition.duration,
8584+
duration: transition.duration
8585+
});
85828586
}
85838587
subgroup.push(node);
85848588
}
@@ -8599,6 +8603,7 @@
85998603
delay: inherit.delay,
86008604
duration: inherit.duration
86018605
};
8606+
inherit = null;
86028607
++lock.count;
86038608
d3.timer(function(elapsed) {
86048609
var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, timer = d3_timer_active, tweened = [];

d3.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/transition/subtransition.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ d3_transitionPrototype.transition = function() {
1313
subgroups.push(subgroup = []);
1414
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
1515
if (node = group[i]) {
16-
transition = Object.create(node.__transition__[id0]);
17-
transition.delay += transition.duration;
18-
d3_transitionNode(node, i, id1, transition);
16+
transition = node.__transition__[id0];
17+
d3_transitionNode(node, i, id1, {time: transition.time, ease: transition.ease, delay: transition.delay + transition.duration, duration: transition.duration});
1918
}
2019
subgroup.push(node);
2120
}

src/transition/transition.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ function d3_transitionNode(node, i, id, inherit) {
6060
duration: inherit.duration
6161
};
6262

63+
inherit = null; // allow gc
64+
6365
++lock.count;
6466

6567
d3.timer(function(elapsed) {

0 commit comments

Comments
 (0)