{"action":"closed","issue":{"url":"https://api.github.com/repos/angular/angular.js/issues/15115","repository_url":"https://api.github.com/repos/angular/angular.js","labels_url":"https://api.github.com/repos/angular/angular.js/issues/15115/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular.js/issues/15115/comments","events_url":"https://api.github.com/repos/angular/angular.js/issues/15115/events","html_url":"https://github.com/angular/angular.js/issues/15115","id":176071628,"number":15115,"title":"Memory leaks in directives with transclusiion","user":{"login":"djfd","id":126338,"avatar_url":"https://avatars.githubusercontent.com/u/126338?v=3","gravatar_id":"","url":"https://api.github.com/users/djfd","html_url":"https://github.com/djfd","followers_url":"https://api.github.com/users/djfd/followers","following_url":"https://api.github.com/users/djfd/following{/other_user}","gists_url":"https://api.github.com/users/djfd/gists{/gist_id}","starred_url":"https://api.github.com/users/djfd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djfd/subscriptions","organizations_url":"https://api.github.com/users/djfd/orgs","repos_url":"https://api.github.com/users/djfd/repos","events_url":"https://api.github.com/users/djfd/events{/privacy}","received_events_url":"https://api.github.com/users/djfd/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/angular/angular.js/labels/resolution:%20works%20as%20expected","name":"resolution: works as expected","color":"207de5"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-09T18:05:21Z","updated_at":"2016-09-09T20:49:07Z","closed_at":"2016-09-09T20:49:07Z","body":"Hi,\r\n\r\nThis affects a scopeless directives with transclusion mode set to 'element', via bindings watchers. (maybe other kinds are affected too, not tested)\r\n\r\nThere is a sample [codepen](http://codepen.io/djFD/pen/KgdPoR)\r\n\r\nWhat is coming there. Every time as you press the button, the directive is removed from DOM, then recreated in the same point. A counter below shows a number of watchers in the scope. So every press gives us a few extra watchers.\r\n\r\nBy the steps.\r\nA.directive 'template' looks like this:\r\n```xml\r\n<container sid=\"{{'container-'+$id}}\">\r\n    container contents\r\n</container>\r\n```\r\nthat is has the only binding at the directive node itself.\r\nB.Directive is scopeless, transclusion mode 'element'\r\n\r\nAt the directive compile time all is going fine, no extra watchers.\r\nThen miracles begins.\r\n\r\nAt entering to pre-link routine we can notice that a watcher for a binding was created. It is good only for a directives with boolean transclusion mode, as nobody can be sure that 'element'-transcluded node will be ever attached to DOM (I mean requested through $tfn) - so why to have a binding activated for it in this point? (please note, there is the only binding, at the topmost directive element only)\r\n\r\nNext, at the post-link, transclusion function is called, and after that we get one more the same binding watcher. This seems to be ok, we need to get it created at this point.\r\n\r\nAt directive removal both cloned node and node placeholder elements are deleted, which does not cause the watchers removal, they are still there. So we got two lost watchers for a single binding.\r\n\r\nWell, it is rather rare to use scopeless transclusion, so in scopeful environment we just cannot notice that because watchers are simply removed together with a scope.\r\n\r\nThat is it. Or am I wrong and just doing something in wrong way?"}}
{"actor":{"display_login":"gkalpak"}}