当前位置:网站首页>What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
2022-07-06 01:15:00 【imkaifan】
Weak reference :
WeakSet The objects in are all weak references , Garbage collection mechanism does not consider WeakSet Reference to the object , in other words , If no other object references that object , Then the garbage collection mechanism will automatically reclaim the memory occupied by the object , Regardless of whether the object still exists in WeakSet In .
This is because the garbage collection mechanism depends on the reachability of objects (reachability) To determine recycling , If the object can still be accessed , The garbage collection mechanism will not free this memory . After you finish using this value , Sometimes I forget to dereference , Causes memory not to be released , This can lead to memory leaks .WeakSet The quotation in it , Not included in the garbage collection mechanism , So there is no such problem . therefore ,WeakSet Suitable for temporary storage of a group of objects , And storing information bound to objects . As long as these objects disappear outside , It's in WeakSet The references in it will disappear automatically .
Because of the above characteristics ,WeakSet Members of are not suitable for reference , Because it will disappear at any time . in addition , because WeakSet How many members are there inside , Depends on whether the garbage collection mechanism is running , It is likely that the number of members before and after running is different , And when the garbage collection mechanism will run is unpredictable , therefore ES6 Regulations WeakSet Non traversal . And of course not size attribute , Because the amount of data is also uncertain .
These features also apply to WeakMap structure
边栏推荐
- Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
- WordPress collection plug-in automatically collects fake original free plug-ins
- Cglib dynamic agent -- example / principle
- Leetcode daily question solution: 1189 Maximum number of "balloons"
- Threedposetracker project resolution
- About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
- Cannot resolve symbol error
- 几百行代码实现一个 JSON 解析器
- Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
- SPIR-V初窥
猜你喜欢

Finding the nearest common ancestor of binary tree by recursion

Convert binary search tree into cumulative tree (reverse middle order traversal)

Study diary: February 13, 2022

Fibonacci number

False breakthroughs in the trend of London Silver

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

MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练

Vulhub vulnerability recurrence 75_ XStream

Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network

Opinions on softmax function
随机推荐
Daily practice - February 13, 2022
IP storage and query in MySQL
How to get the PHP version- How to get the PHP Version?
Interview must brush algorithm top101 backtracking article top34
MCU realizes OTA online upgrade process through UART
Finding the nearest common ancestor of binary search tree by recursion
Kotlin core programming - algebraic data types and pattern matching (3)
Lone brave man
Condition and AQS principle
[pat (basic level) practice] - [simple mathematics] 1062 simplest fraction
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Distributed base theory
Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
servlet(1)
Hundreds of lines of code to implement a JSON parser
MATLB|实时机会约束决策及其在电力系统中的应用
Cve-2017-11882 reappearance
Live broadcast system code, custom soft keyboard style: three kinds of switching: letters, numbers and punctuation
File upload vulnerability test based on DVWA
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】