1

There's a similar question already, but there the issue is resolved as not being due to getImageData itself. This is definitely an issue with getImageData, or else I'm badly misunderstanding something.

The following code consumes about half a meg of memory per second in Chrome 23.0 (Linux), and also leaks, albeit more slowly, on Firefox. Assigning to a local or global variable doesn't help.

Am I missing something? Is this a bug?

<html>
<head>
<script>
function tick() {
    document.getElementById("canvas1").getContext('2d').getImageData(0, 0, 300, 150);
}
setInterval(tick, 10);
</script>
</head>
<body>
<canvas id="canvas1" />
</body>
</html>
Community
  • 1
  • 1
Bakkot
  • 1,175
  • 7
  • 13
  • is it chrome browser ? or chromium ? http://code.google.com/p/chromium/issues/detail?id=16821 – Mehdi Karamosly Dec 19 '12 at 23:23
  • 1
    well.. the code above shouldn't work at all since its the `context` you must get image data from. Anyway my guess is you aren't assigning the data to anything. You are just constantly calling `getImageData` so the data is residing in the memory until the garbage collector can take care of it. – Loktar Dec 19 '12 at 23:24
  • @Loktar I had the wrong code posted; thanks for pointing that out. Code as it stands still leaks. And like I say, assigning the value returned to a local or global doesn't change anything. – Bakkot Dec 19 '12 at 23:27
  • you're rapidly creating a new object every 10 milliseconds, shouldn't it cause a rapid memory growth? Wouldn't you get the same effect if you created an array with 180000 elements every 10 millis? – Matt Greer Dec 19 '12 at 23:35
  • I ran it and memory grew to about 250K and than GC kicked in and dropped it to a normal level. Rinse and repeat. – epascarello Dec 19 '12 at 23:42
  • @MattGreer the new object should get destroyed when it leaves scope (ie instantly), and the memory should be reclaimed. – Bakkot Dec 19 '12 at 23:43
  • 1
    @Bakkot that is true of references and primitives, not so sure it's true of objects in the heap. I believe the GC needs some time to discover they are collectable – Matt Greer Dec 20 '12 at 00:20

0 Answers0