From f78226bc69a572f5478552a9cdc2522e47bdb5eb Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 5 Feb 2015 17:37:47 -0800 Subject: [PATCH] [Plot] Unsubscribe on destroy Unsubscribe when a plot view is destroyed; this avoids resource leaks which cause WTD-840. --- platform/features/plot/src/PlotController.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index ef53efd87f..6449e0f3a1 100644 --- a/platform/features/plot/src/PlotController.js +++ b/platform/features/plot/src/PlotController.js @@ -113,8 +113,20 @@ define( } } + // Release the current subscription (called when scope is destroyed) + function releaseSubscription() { + if (subscription) { + subscription.unsubscribe(); + subscription = undefined; + } + } + + // Subscribe to telemetry when a domain object becomes available $scope.$watch('domainObject', subscribe); + // Unsubscribe when the plot is destroyed + $scope.$on("$destroy", releaseSubscription); + return { /** * Get the color (as a style-friendly string) to use