使用javascript生成的图片内存不能释放 img src方式

2021-03-05 16:07发布

6条回答
jianxiangxiong
2021-03-05 16:55

通过Zepto库释放图片资源的方法。代码如下:

$.fn.remove = function(){    

   return this.each(function(){    

     if(this[removed]){    

       if(this.tagName === 'IMG'){    

         cache.push(this)    

         this.src = '[removed]R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='//让图片资源指向一个空白的gif图片。用cache变量保存dom的引用,60秒。让垃圾回收器有时间回收多余的图片资源。

         if (timeout) clearTimeout(timeout)    

         timeout = setTimeout(function(){ cache = [] }, 60000)    

       }    

       this[removed].removeChild(this)    

     }    

   })    

 }

一周热门 更多>