Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

什么是 GC (浏览器垃圾回收机制)? #22

Open
CodeRookie262 opened this issue Jan 14, 2021 · 1 comment
Open

什么是 GC (浏览器垃圾回收机制)? #22

CodeRookie262 opened this issue Jan 14, 2021 · 1 comment

Comments

@CodeRookie262
Copy link
Owner

No description provided.

@CodeRookie262
Copy link
Owner Author

GC浏览器垃圾回收机制也叫做浏览器内存释放机制,
内存主要分为两种: 堆内存和栈内存;

栈内存释放:

  • 加载页面会加载一个全局上下文(这个上下文只有在页面关闭的时候才会被释放)
  • 函数执行会形成一个私有上下文,当函数进栈执行后执行,当函数执行完毕后所形成的私有上下文一般情况下会被出栈释放掉以此来优化栈内存空间;

堆内存释放:
堆内存的释放主要分为两种,主要分为「查找引用」(Chrome)和「引用计数」(IE)

  • 标记引用: 浏览器在空闲或者指定时间内查看指定堆内存,吧没有被任何东西占用的堆内存给释放掉,占用的话是不会释放的。
  • 计数引用: 创建一个堆内存,被占用一次浏览器就会计数加一,取消占用则计数减一,当计数的数字为 0 时就会被释放掉,某些情况下回导致计数数据混乱出现"内存泄漏"的现象 (如果想深入了解的小伙伴可以去看高程3最后一章)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant