The implementation method of javascript tag removal
This article focuses on "the implementation of javascript tag removal", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "the implementation of javascript tag removal method"!
Tag cleanup is the most commonly used garbage collection method in javascript.
Realization method
1. When a variable enters the execution environment, it is marked as entering the environment.
Logically, the memory occupied by variables that enter the environment can never be released, because as long as the execution stream enters the corresponding environment, it is possible to use it.
When a variable leaves the environment, it is marked as leaving the environment.
When the garbage collector runs, it marks all variables stored in memory. It then removes variables in the environment and tags referenced by variables in the environment. Variables that are then tagged are treated as variables to be deleted because variables in the environment cannot access them. Eventually. The garbage collector clears the memory, destroys the tag values, and reclaims the memory space occupied.
Example
Var m = 0 ~ () n = 19 / / Mark m _ () _ n _ add () as entering the environment. Add (m, n) / / marks a, b, c as entering the environment. Console.log (n) / / a _ r _ b _ r _ c is marked to leave the environment and wait for garbage collection. Function add (a, b) {await + var c = a + b return c} so far, I believe you have a deeper understanding of "the implementation of javascript tag removal". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!