当前位置:网站首页>js中内存泄漏的几种情况
js中内存泄漏的几种情况
2022-08-02 00:14:00 【weixin_46051260】
内存泄漏:由于疏忽或错误造成程序未能释放已经不再使用的内存
1)意外的全局变量
解决方法:严格模式进行检测
例:函数内部定义全局变量(直接赋值)
2)定时器
不用的时候,及时清除定时器
没油及时清除的dom元素,test=null
var main=document.querySelector('.main')
var time=setTimeout(()=>{
var test=document.querySelector('.test')
main.removeChild(test)
console.log(test);
test=null
console.log(test);
if(!test){
clearInterval(time)
}
},2000)
3)闭包
解决办法:赋值为null
4)事件监听
解决办法:在不使用的时候取消事件监听
边栏推荐
- The Statement update Statement execution
- CVPR 2022 | SharpContour:一种基于轮廓变形 实现高效准确实例分割的边缘细化方法
- 460. LFU 缓存
- Don't know about SynchronousQueue?So ArrayBlockingQueue and LinkedBlockingQueue don't and don't know?
- ICML 2022 || 局部增强图神经网络GNN,在 GCN 和 GAT基础上 平均提高了 3.4% 和 1.6%
- BGP综合实验 建立对等体、路由反射器、联邦、路由宣告及聚合
- DFS详解
- Looking back at 5 recessionary times in history: How might this time be different?
- 磁盘与文件系统管理
- BGP 第一次实验
猜你喜欢
Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)
C语言实现扫雷游戏
An interesting project--Folder comparison tool (1)
Web开发
MLX90640 红外热成像仪测温传感器模块开发笔记(十) 成果展示-红眼睛相机
What is Low-Code?What scenarios is low code suitable for?
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
BGP综合实验 建立对等体、路由反射器、联邦、路由宣告及聚合
攻防世界-web-Training-WWW-Robots
unity2D横版游戏教程5-UI
随机推荐
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
思维导图,UML在线画图工具
A simple file transfer tools
业务测试如何避免漏测 ?
ICML 2022 | GraphFM:通过特征Momentum提升大规模GNN的训练
ICML 2022 || 局部增强图神经网络GNN,在 GCN 和 GAT基础上 平均提高了 3.4% 和 1.6%
What does the errorPage attribute of the JSP page directive do?
路由策略
Disk and file system management
C language character and string function summary (2)
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
Multidimensional Correlation Time Series Modeling Method Based on Screening Partial Least Squares Regression of Correlation Variables
Difference between JSP out.print() and out.write() methods
What is it like to trade for a living?
08-SDRAM: Summary
Using the "stack" fast computing -- reverse polish expression
MLX90640 红外热成像仪测温模块开发笔记(完整版)
JSP built-in object out object function introduction
Detailed explanation of JSP request object function
【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】