当前位置:网站首页>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
边栏推荐
- 关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
- How to see the K-line chart of gold price trend?
- SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑
- Introduction to robotics I. spatial transformation (1) posture, transformation
- Modify the ssh server access port number
- What is the most suitable book for programmers to engage in open source?
- vSphere实现虚拟机迁移
- [Arduino syntax - structure]
- 关于softmax函数的见解
- 测试/开发程序员的成长路线,全局思考问题的问题......
猜你喜欢
随机推荐
MYSQL---查询成绩为前5名的学生
网易智企逆势进场,游戏工业化有了新可能
DOM introduction
How to extract MP3 audio from MP4 video files?
DD's command
Getting started with devkit
The basic usage of JMeter BeanShell. The following syntax can only be used in BeanShell
How to see the K-line chart of gold price trend?
VMware Tools installation error: unable to automatically install vsock driver
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
基於DVWA的文件上傳漏洞測試
Study diary: February 13, 2022
[pat (basic level) practice] - [simple mathematics] 1062 simplest fraction
282. Stone consolidation (interval DP)
JVM_ 15_ Concepts related to garbage collection
CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Live broadcast system code, custom soft keyboard style: three kinds of switching: letters, numbers and punctuation
[day 30] given an integer n, find the sum of its factors
Nmap: network detection tool and security / port scanner









