javascript - Why are scopes not destroyed even after $destroy is triggered? -


I have given an instruction that, when clicked, creates a dialog that connects the body using jQuery is. The problem is that when the dialog stops, the scops are never cleaned properly. As shown in the picture, 167 childcaps are preserved. Which dialog matches the amount of items in which NG-repeat instructions are included.

Enter image here details

I have an extremely Tried to make simple version It is my surprise that the scope is actually being removed at each stop in Plnkr, then some, anywhere in production, called $ destroy even after the scope is created due to survival

  link: ($ scope, $ element, $ attr) - & gt; $ Element.on 'click', () - & gt; $ Scope $ Applied () - & gt; Child = $ scope $ New () Template = "" "& lt; span ng-controller =" ListCtrl "& gt; ... list of dialog items ... ... & lt; / span & gt;" "" Compiled Template = $ Collection (Template) (Toddler) Container = Container.CreditDevelopment Container ($ Element) Container.Append (Compiled Template) # Scalup $ scope.closeWidget = () - & gt; Container.trigger ("Container_Coll") Return Container "Container_clause", () - & gt; children. $ Applied () - & gt; $ Has been destroyed, there is still a question:  

What could be the reason for death to survive, trigger and garbage collection?

For obvious reasons I can not show you our production code, though instructions in Plnkr match an IM debugging adequately.

In general, a field (or any other JS object) can not be cleared by GC , If it is still accessible by any other JS object

In practice, whatever jQuery uses in an angular project, it is most likely:

  • An angular service, Controller, scope, or some other object still references your scope object
  • A reference to your object still exists through a DOM element, possibly through an event listener. The DOM element may not be GC-enabled because it is still in the JQuery cache

    Your example, for example, creates a memory leak

    Code: $ scope.removeDialog = () - & gt; to not set > blank $ scope.removeDialog still < Code> child can use the scope referred to by the variable, therefore, this object can not be GC'ed.

    NB: It seems that putting the removeDialog on the hair scope is more appropriate. Your example now works only because the child's scope is not different.


Comments