当前位置:网站首页>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)事件监听
解决办法:在不使用的时候取消事件监听
边栏推荐
猜你喜欢
随机推荐
短视频SEO搜索运营获客系统功能介绍
C语言实现扫雷游戏
基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法
思维导图,UML在线画图工具
146. LRU 缓存
什么是低代码(Low-Code)?低代码适用于哪些场景?
【HCIP】BGP小型实验(联邦,优化)
Grid false data injection attacks detection based on coding strategy
CVPR 2022 | SharpContour:一种基于轮廓变形 实现高效准确实例分割的边缘细化方法
JSP built-in object out object function introduction
How does JSP use request to get the real IP of the current visitor?
IO流基础
Unknown CMake command "add_action_files"
JSP内置对象out对象的功能简介说明
Identify memory functions memset, memcmp, memmove, and memcpy
[Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core
ICML 2022 || 局部增强图神经网络GNN,在 GCN 和 GAT基础上 平均提高了 3.4% 和 1.6%
What does the errorPage attribute of the JSP page directive do?
els block deformation
nodeJs--各种路径









