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

Memory leak with $setValidity #10509

Closed
dlongley opened this issue Dec 17, 2014 · 2 comments
Closed

Memory leak with $setValidity #10509

dlongley opened this issue Dec 17, 2014 · 2 comments

Comments

@dlongley
Copy link
Contributor

If ng-model is used within a form and toggled with ng-if and $setValidity is called on the ngModelController, then a memory leak occurs.

Specifically, the $setValidity call in ngModel (line 3172) adds a validity entry to the parent form controller that keeps a reference to the ngModelController. There's nothing in place to remove this entry if that controller gets destroyed, so these references stick around. Worse, the $setValidity call is added to the ngModelController by creating a closure that wraps the ngModel's element, which can result in leaking quite a bit of memory in complex applications.

This plunker demonstrates the issue by printing out the number of ngModelController references maintained by the form controller each time you toggle a form input off/on.

@pkozlowski-opensource
Copy link
Member

Oh, this sounds bad. We need to fix it in the next patch release.

@pkozlowski-opensource pkozlowski-opensource modified the milestones: 1.3.9, 1.3.8 Dec 18, 2014
@dlongley dlongley changed the title Memory leak w/$setValidity Memory leak with $setValidity Dec 18, 2014
@btford btford modified the milestones: 1.3.8, 1.3.9 Dec 19, 2014
@Narretz Narretz self-assigned this Jan 8, 2015
Narretz added a commit to Narretz/angular.js that referenced this issue Jan 11, 2015
@manikantag
Copy link

Now that new versions of input.js file doesn't have 3172 line, correct line number referred by @dlongley is in v1.3.7: https://github.com/angular/angular.js/blob/v1.3.7/src/ng/directive/input.js#L3172

dlongley added a commit to digitalbazaar/bedrock-angular-form that referenced this issue Jan 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants