zoukankan      html  css  js  c++  java
  • JavaScript 内存释放测试

    JS内部实现垃圾回收机制 无法立即释放 只要数据没有依赖关系 就会在下轮内存回收时清理 

    ! function ()
      {
        var
          array = []
        , count = 100*100*100*5
        , time = +new Date
        
        ; while( count-- )
              array.push( document.createElement('el') )
        
        ; console.log( +new Date - time, array.length )
    
        ; count = 100*100*100*5
        ; time = +new Date
    
        ; while( count-- )
          {
            ; array.pop()          // 无论哪种方法 只要 生成的对象没有依赖 就会被系统释放回收
          //; array[ count ] = null   测试使用null大法 木有用 内存不会立即释放
          //; delete array[ count ]   这种方式在我的浏览器效率超低
          }
    
        ; console.log( +new Date - time, array.length )
    
      }()
    ! function ()
      {
        var
          array = []
        , count = 100*100*100*5
        , time = +new Date
        
        ; while( count-- )
              array.push( document.createElement('el') )
        
        ; console.log( +new Date - time, array.length )
    
        ; array = null      //  只要数据没有引用 内存就会被释放 
    
      }()

  • 相关阅读:
    ES6(二)
    ES6
    bootstrap
    数组对象
    bootstrap
    html5(二)
    css3转换、动画、布局
    整理的一些兼容写法
    css渐变、背景、过渡、分页
    css3(一)
  • 原文地址:https://www.cnblogs.com/doop/p/3896022.html
Copyright © 2011-2022 走看看