Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript memory problem with canvas
    primarykey
    data
    text
    <p>I'm using <code>getImageData</code>/<code>putImageData</code> on a HTML5 canvas to be able to manipulate a picture. My problem is that the browser never seems to <a href="http://jonelf.posterous.com/lite-gc-men-for-sent" rel="nofollow noreferrer">free any memory</a>. Not until I close the tab (tested in Chrome and Opera).</p> <p>Moved these out of the function: <strike></p> <blockquote> <pre><code> var ctx = document.getElementById('leif').getContext('2d'); var imgd = ctx.getImageData(0,0,width,height); var pix = imgd.data; var rndpixel = 0; </code></pre> <p></strike></p> </blockquote> <p>and the problem disappeared!</p> <pre><code>function infiniteLeif() { for (var i = 0; i&lt;65536; i+=4) { rndpixel=Math.floor(Math.random()*(width*(height-2))+width+4) * 4; pix[rndpixel-wx4] = pix[rndpixel]; pix[rndpixel-wx4+1] = pix[rndpixel+1]; pix[rndpixel-wx4+2] = pix[rndpixel+2]; pix[rndpixel+wx4] = pix[rndpixel]; pix[rndpixel+wx4+1] = pix[rndpixel+1]; pix[rndpixel+wx4+2] = pix[rndpixel+2]; pix[rndpixel-4] = pix[rndpixel]; pix[rndpixel-4+1] = pix[rndpixel+1]; pix[rndpixel-4+2] = pix[rndpixel+2]; pix[rndpixel+4] = pix[rndpixel]; pix[rndpixel+4+1] = pix[rndpixel+1]; pix[rndpixel+4+2] = pix[rndpixel+2]; } ctx.putImageData(imgd,0,0); if (go==1) t=setTimeout(infiniteLeif,40); } </code></pre> <p>A full <a href="http://plea.se/me/leif/canvas_leif.html" rel="nofollow noreferrer">example can be found here</a> (Google Chrome is recommended).</p> <p>It's not the <code>setTimeout</code> that is the problem because I tried a loop with the same effect.</p> <p>I've come to understand that removal of circular references often is the key but do I really have one? How can I change this code so that the <a href="https://stackoverflow.com/questions/864516/what-is-javascript-garbage-collection">JavaScript GC</a> gets a chance to do it's job?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload