Note that there are some explanatory texts on larger screens.

plurals
  1. POAngular and Typescript Memory leaks
    primarykey
    data
    text
    <p>In a AngularJS 1.2.5 using TypeScript 0.9.1 app, we are seeing that when we change routes, the private methods on a controller class remain in the heap and leave detached DOM trees in chromes profiler. </p> <p>If we navigate /#/view1 to /#/view2 and back to /3/view1, we end up with view1 controller class in the heap twice and view2 controller class in the heap as well. </p> <p>Our workaround has been to not use private methods anymore.</p> <p>The code generally looks like:</p> <pre><code>module views { app.controller("view1Ctrl", function($scope, $routeParams) { return new view1Ctrl($scope, $routeParams); }); interface Scope extends ng.IScope { TrackingTab: any; } class view1Ctrl { constructor(private $scope: Scope, $routeParams: any) { $scope.TrackingTab = $routeParams["tab"]; $scope.$watch("showTab", (newValue: TrackingTab): void =&gt; { if (newValue === undefined) return; }); } private changeTabToNew(): void { this.$scope.TrackingTab = "new" } } } </code></pre> <p>we have to change to something along the lines of:</p> <pre><code>module views { app.controller("view1Ctrl", function($scope, $routeParams) { return new view1Ctrl($scope, $routeParams); }); interface Scope extends ng.IScope { TrackingTab: any; } class view1Ctrl { constructor(private $scope: Scope, $routeParams: any) { $scope.TrackingTab = $routeParams["tab"]; $scope.$watch("showTab", (newValue: TrackingTab): void =&gt; { if (newValue === undefined) return; }); $scope.changeTabToNew(): void { this.$scope.TrackingTab = "new" }; } } </code></pre> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload