JS中哪些操作会造成内存泄漏
1、 意外的全局变量引起的内存泄漏
function fun(){
leak=’xxx’;//leak会成为一个全局变量,不会被回收
}
2、 闭包引起的内存泄漏
3、 没有清理的DOM元素引用,比如:button,image,text
function removeButton(){
document.body.removeChild(document.getElementById(‘button’));
}
4、 被遗忘的定时器或者回调
5、 子元素存在引用引起的内存泄漏
参考:https://blog.csdn.net/xiasohuai/article/details/82184918https://www.jianshu.com/p/763ba9562864