当前位置:网站首页>How to manually implement the mechanism of triggering garbage collection in node
How to manually implement the mechanism of triggering garbage collection in node
2022-04-23 17:22:00 【Grass like years】
Refer to Ruan Yifeng ES6 Standard in getting started , Manual implementation
node --expose-gc // --expose-gc Indicates that manual garbage collection mechanism is allowed
Then execute the code :
// Perform a garbage collection manually to ensure the accuracy of memory data
> global.gc();
undefined
// View the memory currently occupied , The main concern is heapUsed Field , It's about the size of 4.4MB
> process.memoryUsage();
{ rss: 21626880,
heapTotal: 7585792,
heapUsed: 4708440,
external: 8710 }
// Create a WeakMap
> let wm = new WeakMap();
undefined
// Create an array and assign it to a variable key
> let key = new Array(1000000);
undefined
// take WeakMap The key name of points to the array
// There are two references to the array , One is key, One is WeakMap Key name of
// Be careful WeakMap Is a weak reference
> wm.set(key, 1);
WeakMap { [items unknown] }
// Manual garbage collection once
> global.gc();
undefined
// Check the memory usage again ,heapUsed Has been increased to about 12MB
> process.memoryUsage();
{ rss: 30232576,
heapTotal: 17694720,
heapUsed: 13068464,
external: 8688 }
// Clear variables manually key Reference to array
// Notice that it's not cleared here WeakMap Reference of middle key name to array
> key = null;
null
// Recycle again
> global.gc()
undefined
// View memory usage , Find out heapUsed It's back to its previous size ( It's about 4.8M, Originally for 4.4M, Slightly floating )
> process.memoryUsage();
{ rss: 22110208,
heapTotal: 9158656,
heapUsed: 5089752,
external: 8698 }
版权声明
本文为[Grass like years]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231720179064.html
边栏推荐
- Use of shell sed command
- 1-2 characteristics of nodejs
- Using quartz under. Net core - [1] quick start
- .Net Core3. 1 use razorengine NETCORE production entity generator (MVC web version)
- 1-3 nodejs installation list configuration and project environment
- SiteServer CMS5. 0 Usage Summary
- 快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
- Promise (II)
- JS to find the character that appears three times in the string
- Shortcut keys (multiline)
猜你喜欢
Using quartz under. Net core -- operation transfer parameters of [3] operation and trigger
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
Go language, array, string, slice
stm32入门开发板选野火还是正点原子呢?
Use of five routing guards
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
Simulation of infrared wireless communication based on 51 single chip microcomputer
Lock lock
Detailed explanation of C webpai route
ASP. NET CORE3. 1. Solution to login failure after identity registers users
随机推荐
stm32入门开发板选野火还是正点原子呢?
Deep understanding of control inversion and dependency injection
Clickhouse table engine
Collection of common SQL statements
Detailed explanation of Milvus 2.0 quality assurance system
嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?
Aiot industrial technology panoramic structure - Digital Architecture Design (8)
Document operation II (5000 word summary)
Model problems of stock in and stock out and inventory system
SPC introduction
Scope and scope chain in JS
JS, entries(), keys(), values(), some(), object Assign() traversal array usage
Indexes and views in MySQL
Using quartz under. Net core -- job attributes and exceptions of [4] jobs and triggers
Promise (I)
Solution architect's small bag - 5 types of architecture diagrams
2.Electron之HelloWorld
ECMAScript history
ASP. Net core configuration options (Part 2)
Detailed explanation of C webpai route