JS mechanism 3: stack, heap, garbage collection

ADA in three minutes 2021-02-23 03:53:13
js mechanism stack heap garbage


Language type

  • Static language : You need to confirm the variable data type before using it (c)
  • Dynamic language : The data type needs to be checked during operation (js)
  • Strong type language : Implicit type conversion is not supported
  • Weak type language : Supports implicit type conversion (c、js)

js: You can use the same variable to hold different types of data , There is no need to define the data type of the variable in advance

js data type : Only obj Is a reference type , The rest are primitive types

  1. null

  2. undefined

  3. number

  4. object

  5. string

  6. boolean

  7. symbol: Symbol type

  8. bigint: New number types

    function demo() { var a = " Nuggets " var b = a var c = {name: " Community "} var d = c } // The original type is stored on the stack ( Small space ) in , Reference types are stored in the heap ( The space is large ) in

The stack and heap

Why do we need heap and stack data structures ?

Stack to maintain the context state during program execution , Put all the data on the stack , It will affect the efficiency of context switching , And then affect the execution efficiency of the whole program

// Closure is an object , In the pile , Reference address in stack
function demo() {
var myName = " The Nuggets community "
let test1 = 1
const test2 = 2
var innerFun = {
getName:function(){
console.log(test1)
return myName
},
setName:function(newName){
myName = newName
}
}
return innerFun
}
var test = demo()
test.setName(" Nuggets world ")
test.getName()
console.log(test.getName())
 Copy code 

Garbage collection strategy

  • Manual recycling :c  free()
  • Automatic recovery :js 、 java、 python -> The garbage collector releases memory

Stack recycling :

ESP: A pointer to record the current execution state

After function execution ,ESP Move down to the next execution context , The process is stack destruction of memory

Pile of recycling

Laosheng District : Mark - eliminate 、 Mark - Arrangement

Garbage collection causes a jam ?

js Running on main thread , Once garbage collection is performed , It is necessary to integrate the js Pause , Affect application performance and response performance , To avoid getting stuck , implement Increment mark Algorithm

版权声明
本文为[ADA in three minutes]所创,转载请带上原文链接,感谢
https://qdmana.com/2021/02/20210222181557659N.html

  1. The tapable instance object hook of webpack4. X core tool library
  2. The tapable instance object hook of webpack4. X core tool library
  3. Using libcurl for HTTP communication in C + +
  4. Using libcurl for HTTP communication in C + +
  5. Using CSS variable in Vue
  6. Deeply understand the update of state and props in react
  7. No matter how fast the Internet is, it's useless! In addition to Baidu disk, there is this website slow to let you eat shriveled
  8. Baidu share does not support the solution of HTTPS
  9. [micro front end] the final chapter of micro front end - Qiankun guide and overall exploration of micro front end
  10. [micro front end] the final chapter of micro front end - Qiankun guide and overall exploration of micro front end
  11. Vue cli creates vue3 project
  12. Nginx reverse proxy for windows authentication using NTLM
  13. Rust tutorial: introduction to rust for JavaScript developers
  14. Deploying personal blog to Tencent cloud with serverless framework
  15. R & D solution e-Car front end monitoring system
  16. JavaScript advanced learning
  17. Spend 1 minute to master these 5 ppt tips, courseware making less detours
  18. Vue: vuex persistent state
  19. React native gets the current network state of the device Netinfo
  20. High performance nginx HTTPS tuning - how to speed up HTTPS by 30%
  21. JavaScript advanced: Javascript object-oriented, JavaScript built-in object, JavaScript BOM, JavaScript encapsulation
  22. JavaScript advanced: Javascript object-oriented, JavaScript built-in object, JavaScript BOM, JavaScript encapsulation
  23. Vue determines whether the El form in the elementui is updated or changed. If it changes, it will prompt whether to save it. If it does not change, it will leave directly
  24. Algorithm problem: sum of two numbers -- JavaScript and Java implementation
  25. High performance nginx HTTPS tuning
  26. JQuery advanced
  27. day 30 jQuery
  28. JQuery:JQuery Basic syntax, jQuery selector, jQuery DOM, comprehensive case check box, comprehensive case random picture
  29. TCP/IP 开胃菜 之 HTTP
  30. JQuery:JQuery Basic syntax, jQuery selector, jQuery DOM, comprehensive case check box, comprehensive case random picture
  31. JavaScript data type
  32. [micro front end] the final chapter of micro front end - Qiankun guide and overall exploration of micro front end
  33. Solve Ajax cross domain problem [5 solutions]
  34. HTTP of TCP / IP appetizer
  35. Optimization of pod creation efficiency in serverless scenario
  36. Iqiyi Sports: experience the ultimate expansion and contraction of serverless, and increase the utilization rate of resources by 40%
  37. First knowledge of HTTP / 1.1
  38. First knowledge of HTTP / 1.1
  39. Webpack learning notes series 05 devserver
  40. Webpack learning notes series 04 - resource processing optimization
  41. How to build a high performance front end intelligent reasoning engine
  42. How to become a professional front end engineer in 2021?
  43. How to transform single / micro service application into serverless application
  44. How to transform single / micro service application into serverless application
  45. How to transform single / micro service application into serverless application
  46. How to connect the ground gas to the micro front end?
  47. How to connect the ground gas to the micro front end?
  48. How to connect the ground gas to the micro front end?
  49. Vue server rendering principle analysis and introduction
  50. Realize the correct loading of text message
  51. Building my own project scaffolding with yeoman
  52. JavaScript advanced prototype and prototype chain
  53. React background management front end system (based on open source framework development) start
  54. JS practical skills breakpoint debugging
  55. I'd like to share with you 20 super easy-to-use Chrome extension plug-ins
  56. Get page element location
  57. Use the powerful API of modern browser to record any interface in the browser and realize export, save and management
  58. Delayed code execution in flutter
  59. Reconfiguration experience of KOA middleware system
  60. Add comments to your blog