Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Memory leak in angular 1.5 #16698

Closed
Closed
@atishayv

Description

@atishayv

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:

  1. By assigning the controller variables to null
  2. Not assigning the controller variables to null

AngularJS version: 1.5

Browser: [Chrome XX | Edge XX ]

Anything else:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions