Skip to content

AngularJS directive memory leak #5

@ufocoder

Description

@ufocoder

Project need an example for AngularJS directive memory leak with URL to live example on JSFiddle (or something like that)

For example there's a memory leak

function(scope, element, attrs) {  
  element.on('click', function() {
    scope.selected = true
  })
}

And it could be fixed like the following:

function(scope, element, attrs) {  
  element.on('click', function() {
    scope.selected = true
  })
  scope.$on('$destroy', function() {
    element.off() // deregister all event handlers
  })
}

By the way for more information about memory leaks in AngularJS you could read here

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions