Does JavaScript setInterval() method cause memory leak?

前端 未结 8 1654
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:42

    The problem here is not in the code itself, it doesn't leak. It is because of the way Timeline panel is implemented. When Timeline records events we collect JavaScript stack traces on each invocation of setInterval callback. The stack trace is first allocated in JS heap and then copied into native data structures, after the stack trace is copied into the native event it becomes garbage in the JS heap. This is reflected on the graph. Disabling the following call http://trac.webkit.org/browser/trunk/Source/WebCore/inspector/TimelineRecordFactory.cpp#L55 makes the memory graph flat.

    There is a bug related to this issue: https://code.google.com/p/chromium/issues/detail?id=120186

提交回复
热议问题