Does JavaScript setInterval() method cause memory leak?

前端 未结 8 1664
Happy的楠姐
Happy的楠姐 2020-11-29 22:15

Currently developing a JavaScript based animation project.

I have noticed that, proper use of setInterval(), setTimeout() and even re

8条回答
  •  情话喂你
    2020-11-29 22:30

    Chrome is hardly seeing any memory pressure from your program (1.23 MB is very low memory usage by today's standards), so it probably does not think it needs to GC aggressively. If you modify your program to use more memory, you will see the garbage collector kick in. e.g. try this:

    
    
    
    Where goes memory?
    
    
    
    Greetings!
    
    
    
    
    
    

    When I run this, I get a saw tooth memory usage pattern, peaking bellow around 13.5MB (again, pretty small by today's standards).

    PS: Specifics of my browsers:

    Google Chrome   23.0.1271.101 (Official Build 172594)
    OS  Mac OS X
    WebKit  537.11 (@136278)
    JavaScript  V8 3.13.7.5
    Flash   11.5.31.5
    User Agent  Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.101 Safari/537.11
    

提交回复
热议问题