Skip to content

Commit a1b4dd2

Browse files
authored
Merge pull request #1821 from dfcreative/mem-unleak
Fix scatter camera memory leak
2 parents f3697a8 + 888ee1b commit a1b4dd2

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/plots/gl2d/scene2d.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ proto.destroy = function() {
374374
this.fullData = null;
375375
this.glplot = null;
376376
this.stopped = true;
377+
this.camera.mouseListener.enabled = false;
378+
this.mouseContainer.removeEventListener('wheel', this.camera.wheelListener);
379+
this.camera = null;
377380
};
378381

379382
proto.plot = function(fullData, calcData, fullLayout) {

src/plots/gl3d/camera.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function createCamera(element, options) {
181181
});
182182

183183
var lastX = 0, lastY = 0, lastMods = {shift: false, control: false, alt: false, meta: false};
184-
mouseChange(element, handleInteraction);
184+
camera.mouseListener = mouseChange(element, handleInteraction);
185185

186186
// enable simple touch interactions
187187
element.addEventListener('touchstart', function(ev) {
@@ -247,7 +247,7 @@ function createCamera(element, options) {
247247
return true;
248248
}
249249

250-
mouseWheel(element, function(dx, dy) {
250+
camera.wheelListener = mouseWheel(element, function(dx, dy) {
251251
if(camera.keyBindingMode === false) return;
252252

253253
var flipX = camera.flipX ? 1 : -1;

src/plots/gl3d/scene.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,11 @@ proto.plot = function(sceneData, fullLayout, layout) {
593593
};
594594

595595
proto.destroy = function() {
596+
this.camera.mouseListener.enabled = false;
597+
this.container.removeEventListener('wheel', this.camera.wheelListener);
598+
this.camera = this.glplot.camera = null;
596599
this.glplot.dispose();
597600
this.container.parentNode.removeChild(this.container);
598-
599-
// Remove reference to glplot
600601
this.glplot = null;
601602
};
602603

0 commit comments

Comments
 (0)