Javascript garbage collection method

Javascript garbage collection method

Clear labeling (mark and sweep)

  • This is the JavaScript most common form of garbage collection, when the variable into the execution environment, such as a function to declare a variable, the garbage collector to mark it as "into the environment", when variable leaving the environment (end of function execution) to labeled "leave environment"
  • The garbage collector will give all variables are stored in memory marked at run time, and then remove the environment variables and variables (closures) are referenced by the environment variable, there are still marked after this is done is to delete variables

Reference count (reference counting)

  • Often occur in low memory leak versions of IE, many times, because it uses reference counting garbage collection. The strategy is to reference count the number of times a track record of each value is used when you declare a variable and a reference citations when the type of the variable assigned to this value is increased by one, if the value of the variable into another , then this is worth quoting decremented by 1, when this value becomes a reference number 0, indicating that no variable is in use, this value can not be accessed, so that the space occupied may be recovered, so the garbage collector will running time to clean out the reference number of the space occupied by the value 0

Reference link Memory Management -MDN

Guess you like

Origin www.cnblogs.com/nayek/p/11728899.html