• 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      //  只要数据没有引用 内存就会被释放 
    
      }()

  • 相关阅读:
    vue 基础
    Bootstrap 基础
    FormatMessage函数
    CreateProcess中的部分参数理解
    关于远程线程的调用
    利用服务枚举进程
    FindQQByProcess
    寻找kernel32.dll的地址
    ShellCode的几种调用方法
    操作系统版本
  • 原文地址:https://www.cnblogs.com/doop/p/3896022.html
Copyright © 2020-2023  润新知