Does JavaScript setInterval() method cause memory leak?

Currently developing a JavaScript based animation project.

I have noticed that, proper use of setInterval(), setTimeout() and even requestAnimationFrame allocates memory without my request, and causes frequent garbage collection calls. More GC calls = flickers :-(

For instance; when I execute the following simple code by calling init() in Google Chrome, memory allocation + garbage collection is fine for the first 20-30 seconds...

function init()
    var ref = window.setInterval(function() { draw(); }, 50);

function draw()
    return true

Somehow, within a minute or so, starts a strange increase in allocated memory! Since init() is called only for once, what is the reason for the increase in allocated memory size?

(Edit: chrome screenshot uploaded)

chrome screenshot

NOTE #1: Yes, I have tried calling clearInterval() before the next setInterval(). Problem remains the same!

NOTE #2: In order to isolate the problem, I'm keeping the above code simple and stupid.



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.