当前位置:网站首页>什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
2022-07-06 01:13:00 【imkaifan】
弱引用:
WeakSet 中的对象都是弱引用,垃圾回收机制不考虑 WeakSet 对该对象的引用,也就是说,如果其他对象都不再引用该对象,那么垃圾回收机制会自动回收该对象所占用的内存,不考虑该对象还存在于 WeakSet 之中。
这是因为垃圾回收机制根据对象的可达性(reachability)来判断回收,如果对象还能被访问到,垃圾回收机制就不会释放这块内存。结束使用该值之后,有时会忘记取消引用,导致内存无法释放,进而可能会引发内存泄漏。WeakSet 里面的引用,都不计入垃圾回收机制,所以就不存在这个问题。因此,WeakSet 适合临时存放一组对象,以及存放跟对象绑定的信息。只要这些对象在外部消失,它在 WeakSet 里面的引用就会自动消失。
由于上面这个特点,WeakSet 的成员是不适合引用的,因为它会随时消失。另外,由于 WeakSet 内部有多少个成员,取决于垃圾回收机制有没有运行,运行前后很可能成员个数是不一样的,而垃圾回收机制何时运行是不可预测的,因此 ES6 规定 WeakSet 不可遍历。而且自然也就没有size属性,因为有多少数据量也是不确定的。
这些特点同样适用于 WeakMap 结构
边栏推荐
- SCM Chinese data distribution
- After 95, the CV engineer posted the payroll and made up this. It's really fragrant
- Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
- Building core knowledge points
- Leetcode1961. 检查字符串是否为数组前缀
- Development trend of Ali Taobao fine sorting model
- Who knows how to modify the data type accuracy of the columns in the database table of Damon
- [groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
- Leetcode 208. 实现 Trie (前缀树)
- Pbootcms plug-in automatically collects fake original free plug-ins
猜你喜欢

Finding the nearest common ancestor of binary search tree by recursion

The growth path of test / development programmers, the problem of thinking about the overall situation

Fibonacci number
![[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)](/img/dd/bffe27b04d830d70f30df95a82b3d2.jpg)
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)

ADS-NPU芯片架构设计的五大挑战

Starting from 1.5, build a micro Service Framework - call chain tracking traceid

测试/开发程序员的成长路线,全局思考问题的问题......

ThreeDPoseTracker项目解析

1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once

servlet(1)
随机推荐
Programmer growth Chapter 9: precautions in real projects
Lone brave man
Daily practice - February 13, 2022
[day 30] given an integer n, find the sum of its factors
FFT 学习笔记(自认为详细)
Modify the ssh server access port number
Distributed base theory
有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀
程序员成长第九篇:真实项目中的注意事项
MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练
Recursive method to realize the insertion operation in binary search tree
Convert binary search tree into cumulative tree (reverse middle order traversal)
Who knows how to modify the data type accuracy of the columns in the database table of Damon
Three methods of script about login and cookies
esxi的安装和使用
SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑
The basic usage of JMeter BeanShell. The following syntax can only be used in BeanShell
ORA-00030
Vulhub vulnerability recurrence 74_ Wordpress
Gartner released the prediction of eight major network security trends from 2022 to 2023. Zero trust is the starting point and regulations cover a wider range