jquery - JavaScript: Memory leak on canvas (not in Chrome) -
i'm trying draw gradient lines on canvas, using jcanvas plugin , jquery code leads memory leak in firefox (reserved ram increases infinity). internet explorer deals ram usage quite whole thing incredibly slow. google chrome displays canvas without lag. tell me doing wrong?
parts of code:
declarations:
var i, i1, i2, p; var r=[], g=[], b=[], a=[]; var gradient=[]; var w=$("body").width(); var w2=math.floor(w/2), w3=w2-1; var h=$("body").height();
drawing:
function draw() { $('#bg').clearcanvas(); (i=0; i<w2; i++) { $('#bg').drawline({ strokestyle: gradient[i], strokewidth: 2, x1: i*2, y1: 0, x2: i*2, y2: 700, }); } }
recalculating values of lines colours
function mixer() { (i=0; i<w2; i++) { p = math.random(); if (p<0.997) { i1 = (i>1)?i-1:w3; i2 = (i<w3)?i+1:0; r[i] = math.floor(( r[i1] + r[i2] ) / 2); g[i] = math.floor(( g[i1] + g[i2] ) / 2); b[i] = math.floor(( b[i1] + b[i2] ) / 2); } else { r[i] = math.floor(math.random()*180); g[i] = math.floor(math.random()*180); b[i] = math.floor(math.random()*180); } delete gradient[i]; gradient[i] = $("#bg").creategradient({ x1: 0, y1: 0, x2: 1, y2: 699, c1: '#000', c2: "rgb("+r[i]+","+g[i]+","+b[i]+")", c3: '#000' }); } draw(); } window.setinterval(mixer, 60);
test if better that:
function mixer() { (i = 0; < w2; i++) { p = math.random(); if (p < 0.997) { i1 = (i > 1) ? - 1 : w3; i2 = (i < w3) ? + 1 : 0; r[i] = math.floor((r[i1] + r[i2]) / 2); g[i] = math.floor((g[i1] + g[i2]) / 2); b[i] = math.floor((b[i1] + b[i2]) / 2); } else { r[i] = math.floor(math.random() * 180); g[i] = math.floor(math.random() * 180); b[i] = math.floor(math.random() * 180); } delete gradient[i]; gradient[i] = $("#bg").creategradient({ x1: 0, y1: 0, x2: 1, y2: 699, c1: '#000', c2: "rgb(" + r[i] + "," + g[i] + "," + b[i] + ")", c3: '#000' }); } draw(); settimeout(mixer, 60); } mixer();
Comments
Post a Comment