Memory leak in angular 1.5 #16698
Description
I'm submitting a ...
- bug report
- feature request
- other
Current behavior:
Currently in order for controller variables to be garbage collected, I have to reset all variables assigned to this
object to null
on destroy of controller. Ex :
class SampleController {
constructor($scope, $rootScope, dependencyA) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.dependencyA = dependencyA;
}
$onInit() {
this.bindingA = 'Some value';
this.bindingB = {key : 'Some Object'};
this.bindingC = ['A', 'B', 'C'];
}
$onDestroy() {
this.bindingA = null;
this.bindingB = null;
this.bindingC = null;
}
}
If i don't reset all the variables in $onDestroy
, the values will never be garbage collected.
Expected / new behavior:
Shouldn't the values assigned to this object automatically set to null when controller is destroyed ?
If not, what is the expected way to write code ? Because it's a cumbersome job to set all controller variables to null on destroy of each controller.
Minimal reproduction of the problem with instructions:
On comparing the heap snapshot in debugger of below 2 scenarios:
- By assigning the controller variables to null
- Not assigning the controller variables to null
AngularJS version: 1.5
Browser: [Chrome XX | Edge XX ]
Anything else: