Skip to content

Commit

Permalink
[Time Conductor] Fixed memory leak due to listeners not being deregis…
Browse files Browse the repository at this point in the history
…tered
  • Loading branch information
akhenry committed Oct 24, 2016
1 parent 49e600d commit a942541
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ define(

ConductorAxisController.prototype.destroy = function () {
this.conductor.off('timeSystem', this.changeTimeSystem);
this.conductor.off('bounds', this.setScale);
this.conductor.off('bounds', this.changeBounds);
this.conductorViewService.off("zoom", this.onZoom);
this.conductorViewService.off("zoom-stop", this.onZoomStop)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ define(
this.conductor.on('timeOfInterest', this.changeTimeOfInterest);
this.conductorViewService.on('zoom', this.setOffsetFromBounds);
this.conductorViewService.on('pan', this.setOffsetFromBounds);
this.conductor.on('timeSystem', this.changeTimeSystem);

var timeOfInterest = this.conductor.timeOfInterest();
if (timeOfInterest) {
Expand All @@ -55,8 +54,7 @@ define(
}

ConductorTOIController.prototype.destroy = function () {
this.conductor.off('timeOfInterest', this.setOffsetFromBounds);
this.conductor.off('timeSystem', this.changeTimeSystem);
this.conductor.off('timeOfInterest', this.changeTimeOfInterest);
this.conductorViewService.off('zoom', this.setOffsetFromBounds);
this.conductorViewService.off('pan', this.setOffsetFromBounds);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ define(
var timeSystem = this.conductor.timeSystem();
if (timeSystem) {
this.setFormFromTimeSystem(timeSystem);
this.supportsZoom = timeSystem.defaults().zoom !== undefined;
}

//Represents the various modes, and the currently selected mode
Expand Down Expand Up @@ -108,7 +107,7 @@ define(
};

TimeConductorController.prototype.destroy = function () {
this.conductor.off('bounds', this.setFormFromBounds);
this.conductor.off('bounds', this.changeBounds);
this.conductor.off('timeSystem', this.changeTimeSystem);

this.conductorViewService.off('pan', this.onPan);
Expand Down Expand Up @@ -186,6 +185,8 @@ define(
timeSystemModel.selected = timeSystem;
timeSystemModel.format = timeSystem.formats()[0];
timeSystemModel.deltaFormat = timeSystem.deltaFormat();
this.supportsZoom = timeSystem.defaults().zoom !== undefined;

if (this.supportsZoom) {
timeSystemModel.minZoom = timeSystem.defaults().zoom.min;
timeSystemModel.maxZoom = timeSystem.defaults().zoom.max;
Expand Down Expand Up @@ -265,16 +266,14 @@ define(
*/
TimeConductorController.prototype.changeTimeSystem = function (newTimeSystem) {
if (newTimeSystem && (newTimeSystem !== this.$scope.timeSystemModel.selected)) {
this.setFormFromTimeSystem(newTimeSystem);
if (newTimeSystem.defaults()) {
var deltas = newTimeSystem.defaults().deltas || {start: 0, end: 0};
var bounds = newTimeSystem.defaults().bounds || {start: 0, end: 0};

this.setFormFromDeltas(deltas);
this.setFormFromBounds(bounds);

this.supportsZoom = newTimeSystem.defaults().zoom !== undefined;
}
this.setFormFromTimeSystem(newTimeSystem);
}
};

Expand Down
2 changes: 1 addition & 1 deletion platform/features/plot/src/PlotController.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ define(
if (handle) {
handle.unsubscribe();
handle = undefined;
conductor.off(changeTimeOfInterest);
conductor.off("timeOfInterest", changeTimeOfInterest);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/api/TimeConductor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ define(['EventEmitter'], function (EventEmitter) {

TimeConductor.prototype = Object.create(EventEmitter.prototype);

TimeConductor.prototype.on = function (event) {
EventEmitter.prototype.on.apply(this, arguments);
};

/**
* Validate the given bounds. This can be used for pre-validation of
* bounds, for example by views validating user inputs.
Expand Down

0 comments on commit a942541

Please sign in to comment.