Memory (heap, stack, queue)

Stack: last in first out after an advanced, tennis cartridge (operation sequence context)
stack: tree, shelves and similar to the book (JSON)
queue: FIFO, queue as security check (event loop)
and C / different C ++, JavaScript and does not distinguish between stack memory and heap memory in the strict sense, so we can understand the simple and crude JavaScript for all data are stored in the heap memory

JavaScript execution context -> variable object (stored basic data type) -> stored in the heap memory
reference data types -> stored in the heap memory -> reference to the operation target -> stored in the address of a variable object

JavaScript garbage collection mechanism
to identify those values are no longer continue to use, and then free up memory. Garbage collector performs a fixed period of time once every release operation.
JavaScript memory life cycle

  1. You need to allocate memory
  2. Use memory allocated (read, write)
  3. When it does not need to be released, return

In JavaScript, the most commonly used by the algorithm to find the mark clear which objects are no longer continue to use, so a = null actually just made a reference to the release of the operation, so that a value corresponding to the loss of the original references, from execution environment, this value will be found and released the next operation is performed garbage collector. The dereference at the appropriate time, is an important way to get better performance for the page.

Local scope, function completes, the local variable will be no longer necessary, so the garbage collector very easy to make judgments and recycling.
But when the global variable to be automatically free up memory space it is difficult to judge, so in our development, it is necessary to avoid the use of global variables.

Guess you like

Origin www.cnblogs.com/bingery/p/11301418.html