JavaScript advanced programming (study notes)
Memory Allocation
1. STACK: managed by a computer, fast but not free to stack: Controlled by programmers, free
2. The reference type is stored in the heap, and the value type is stored in the place where it is declared.
2. Garbage Collection
1. Find out the unused variables (no stack memory points to it in the heap memory) and release the occupied memory. However, this process is not always because of its high overhead, therefore, the garbage collector periodically runs at a fixed interval.
2. The exit scope tag can be deleted. Most browsers use this method for garbage collection. The difference is how to mark and separate garbage collection.
3. JavaScript objects are marked and cleared for garbage collection, but non-JavaScript native objects (BOM, DOM) are called multiple times by reference counting to recycle garbage, memory leakage occurs during cyclic calling. The solution is to release the reference.
4. Remove the global variable reference (var a = null) so that the corresponding local variable can be found at the next running of the garbage collector.
5. The garbage collection function of IE6 runs based on the memory allocation volume. However, if a large number of variables exist in the environment, the garbage collection function remains in the running state. IE7 has made some adjustments, the trigger condition is not fixed, but is modified dynamically. The initial value is the same as that of IE6. If the Garbage Collector recycles a memory allocation less than 15% of the memory occupied by the program, this will double the street conditions, if the recycled memory is higher than 85%, it indicates that most of the memory should have been cleared up. At this time, the trigger condition is set back.
Three reference types
1 object
Var person = {};
Person. name = "tom ";
Var param = "name ";
Alert (person [param]); // tom
Alert (person. param); // undefined
2, Array
(1) var options = [1, 2,]
In earlier versions of IE8, an array containing 1, 2, and undefined items is generated. other browsers only generate 1, 2
(2) sort method
Var arr = [3, 6, 1, 2, 9];
Function compare (a, B ){
If (a <B)
Return 1
Else
Return-1
}
Alert (arr. sort (compare); // 9 6 3 2 1
When there are too many threads, there are too many threads.