当前位置:网站首页>什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
2022-07-06 01:13:00 【imkaifan】
弱引用:
WeakSet 中的对象都是弱引用,垃圾回收机制不考虑 WeakSet 对该对象的引用,也就是说,如果其他对象都不再引用该对象,那么垃圾回收机制会自动回收该对象所占用的内存,不考虑该对象还存在于 WeakSet 之中。
这是因为垃圾回收机制根据对象的可达性(reachability)来判断回收,如果对象还能被访问到,垃圾回收机制就不会释放这块内存。结束使用该值之后,有时会忘记取消引用,导致内存无法释放,进而可能会引发内存泄漏。WeakSet 里面的引用,都不计入垃圾回收机制,所以就不存在这个问题。因此,WeakSet 适合临时存放一组对象,以及存放跟对象绑定的信息。只要这些对象在外部消失,它在 WeakSet 里面的引用就会自动消失。
由于上面这个特点,WeakSet 的成员是不适合引用的,因为它会随时消失。另外,由于 WeakSet 内部有多少个成员,取决于垃圾回收机制有没有运行,运行前后很可能成员个数是不一样的,而垃圾回收机制何时运行是不可预测的,因此 ES6 规定 WeakSet 不可遍历。而且自然也就没有size属性,因为有多少数据量也是不确定的。
这些特点同样适用于 WeakMap 结构
边栏推荐
- 新手入门深度学习 | 3-6:优化器optimizers
- Some features of ECMAScript
- 视频直播源码,实现本地存储搜索历史记录
- ThreeDPoseTracker项目解析
- Recursive method to realize the insertion operation in binary search tree
- Use of crawler manual 02 requests
- [groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
- Redis' cache penetration, cache breakdown, cache avalanche
- 基於DVWA的文件上傳漏洞測試
- Getting started with devkit
猜你喜欢
基于DVWA的文件上传漏洞测试
Vulhub vulnerability recurrence 74_ Wordpress
The population logic of the request to read product data on the sap Spartacus home page
Ubantu check cudnn and CUDA versions
Finding the nearest common ancestor of binary tree by recursion
毕设-基于SSM高校学生社团管理系统
SSH login is stuck and disconnected
Differences between standard library functions and operators
关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
随机推荐
Cf:h. maximum and [bit operation practice + K operations + maximum and]
Recursive method to realize the insertion operation in binary search tree
DD's command
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
VMware Tools installation error: unable to automatically install vsock driver
Recoverable fuse characteristic test
View class diagram in idea
面试必刷算法TOP101之回溯篇 TOP34
False breakthroughs in the trend of London Silver
cf:C. The Third Problem【关于排列这件事】
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
[day 30] given an integer n, find the sum of its factors
In the era of industrial Internet, we will achieve enough development by relying on large industrial categories
Beginner redis
基于DVWA的文件上传漏洞测试
Logstash clear sincedb_ Path upload records and retransmit log data
For a deadline, the IT fellow graduated from Tsinghua suddenly died on the toilet
esxi的安装和使用
Dynamic programming -- linear DP
servlet(1)