-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ngInclude leaks if template contains comments #1620
Comments
plnkr.co example would be helpful. any comment e.g. |
Yep, any comment seems to do it. The leak occurs whenever the content is torn down, e.g. src changing, inside nested ng-repeat, etc. I'll try to put a standalone sample together if I get time. |
Right, I've slightly mislead you with my previous statements so I'll give you the full history. We are currently using angular (with require) to dynamically load/unload widgets written in angular. Each widget is isolated as an Angular application. When un-installing our widgets we have come across 3 separate leaks.
If you look at the last comment on this issue #1537 you will find our rather hacky fix to this. Ideally I think subscriptions to document/window events should be managed by a service tied to the root scope, when the rootElement is destroyed that service could then unhook all events automatically. Once you get around the browser issue, I think the other two issues are actually related. They both stem from the fact that the element supplied to compile is not necessarily the same as the element passed to link. This is due to the cloning that occurs during transclusion.
Hope that makes sense |
Any update on this issue? The initial response was quick, but its been over a month now.... |
I can't reproduce the ng-include leak as you describe. This is what I tried: http://plnkr.co/edit/l0M31vYlZCm5VC6vRChk?p=preview plain old comments should not leak any DOM nodes. we however use comments to mark a place in the dom was fully transcluded (like ngRepeat or ngSwitch), so that's likely what you've seen. the comments in this case are just a symptom and not the cause. you are right about the ngSwitch leak - that is a valid one, but I don't see how without ngSwitch ngInclude leaks any memory. lastly #1537 does offer have some good suggestions that we should implement. I'm going to close this issue and fix ngSwitch. if you can repro the leak without global destruction of the app or without ngSwitch then please reopen it and provide repro instructions. |
The ngInclude directive leaks if your template contains comments. For some reason Angular seems to associate random scope objects with comments. When jQuery.cleanData is eventually called it performs a getElementsByName('*'). As comment nodes and text nodes are not included in this selector the scopes associated with the comments are not cleared. Also, due to scope prototype inheritance, all parent scopes are also leaked.
The text was updated successfully, but these errors were encountered: