Skip to content

Commit 0593bde

Browse files
committed
Fix memory leak in bar chart, part 2.
Chrome helpfully disables requestAnimationFrame in background tabs. It also slows setInterval rates. However, it does not stop setIntervals completely; therefore, this example in a background tab would continuously schedule transitions that never wake up. Flushing the timer queue explicitly guarantees that scheduled transitions have a chance to end when in the background.
1 parent 04eae18 commit 0593bde

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

tutorial/bar-2.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ setInterval(function() {
475475
redraw1();
476476
redraw2();
477477
redraw3();
478+
d3.timer.flush(); // avoid memory leak when in background tab
478479
}, 1500);
479480

480481
</script>

0 commit comments

Comments
 (0)