How to find JS Memory Leaks?

后端 未结 7 1649
既然无缘
既然无缘 2020-12-02 05:19

I have struggled around with the heap profiler in chrome but it is very confusing. Especially if there are minimized libraries inside. But even the DOMElements views, elemen

7条回答
  •  盖世英雄少女心
    2020-12-02 05:36

    I don't see mentioned window.performance.memory, which gives you the run-time ability to monitor and take action based on memory usage.

    window.performance.memory:
    
    MemoryInfo {
      totalJSHeapSize: 7084834,
      usedJSHeapSize: 6486770,
      jsHeapSizeLimit: 4294705152
    }
    

    For a handy percentage, use this:

    window.performance.memory.usedJSHeapSize / window.performance.memory.jsHeapSizeLimit
    

    https://developer.mozilla.org/en-US/docs/Web/API/Window/performance

提交回复
热议问题