当前位置:网站首页>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)事件监听
解决办法:在不使用的时候取消事件监听
边栏推荐
- [HCIP] BGP Small Experiment (Federation, Optimization)
- els block deformation judgment.
- Double queue implementation stack?Dual stack implementation queue?
- Pytorch seq2seq 模型架构实现英译法任务
- 632. 最小区间
- nodeJs--mime module
- ICML 2022 || 局部增强图神经网络GNN,在 GCN 和 GAT基础上 平均提高了 3.4% 和 1.6%
- bgp aggregation reflector federation experiment
- Multidimensional Correlation Time Series Modeling Method Based on Screening Partial Least Squares Regression of Correlation Variables
- 扑克牌问题
猜你喜欢

实现删除-一个字符串中的指定字母,如:字符串“abcd”,删除其中的”a”字母,剩余”bcd”,也可以传递多个需要删除的字符,传递”ab”也可以做到删除”ab”,剩余”cd”。

PHP从txt文件中读取数据的方法

An interesting project--Folder comparison tool (1)

Don't concatenate strings with jOOQ

BGP first experiment

CVPR 2022 | SharpContour:一种基于轮廓变形 实现高效准确实例分割的边缘细化方法

Kunpeng compile and debug plug-in actual combat

Realize deletion - a specified letter in a string, such as: the string "abcd", delete the "a" letter in it, the remaining "bcd", you can also pass multiple characters to be deleted, and pass "ab" can

字符串分割函数strtok练习

How to find new potential projects?Tools recommended
随机推荐
Kunpeng compile and debug plug-in actual combat
Redis - message publish and subscribe
146. LRU cache
JSP out.write()方法具有什么功能呢?
How does JSP use request to get the real IP of the current visitor?
IO流基础
思维导图,UML在线画图工具
els block deformation judgment.
Don't know about SynchronousQueue?So ArrayBlockingQueue and LinkedBlockingQueue don't and don't know?
鲲鹏编译调试插件实战
Disk and file system management
Detailed explanation of JSP request object function
[21-Day Learning Challenge] A small summary of sequential search and binary search
How to design a circular queue?Come and learn~
uni-app project summary
基于超参数自动寻优的工控网络入侵检测
BGP first experiment
Business test how to avoid missing?
不要用jOOQ串联字符串
Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)