Some notes JS garbage collection

Garbage collector periodically (periodic) identify variables no longer continue to use, and then release its memory, different periods of the browser, there are two common garbage collection.
 
Clear labeling (conventional)
    The browser will all reference variables marked, then the global variable references and clear labeling of closures. In performing js code will enter an execution environment, when leaving the current execution environment, the implementation of the current variable labeled internal environment will be cleared, most browsers are using this way.
Reference count (IE7 / 8, Netscape Navigator3)
    Each time a reference variable, the reference count will +1, if the value is assigned to another referenced, then +1 contrary, when the variable reference value if the references to other variables, it will -1, when reference number is 0, the garbage collector will be cleared.
 
Reference counting problems -> (circular references)
    (IE js part of the object has not used the native, C ++ uses a COM object to simulate analog, its reference counting garbage collection mechanism is used, when a reference cycles, will be greatly occupied memory.)
Solution -> Manual dereference cycle
    After you are finished manually set it to null, the variable is set to a value of null means cutting off contact with its variable previously referenced, the next time the garbage collector runs, it will remove these values ​​and to recover their occupied memory

Guess you like

Origin www.cnblogs.com/asablog/p/11608082.html