gongzhitaao
gongzhitaao

Reputation: 6682

Do out-of-view objects on Canvas consume memory?

If I'm continuously drawing objects on canvas, and moving the old objects out of boundary, does the old object still consume memory?

For example this jsfiddle

var canvas = d3.select("body").append("canvas")
                .attr("width", 200)
                .attr("height", 200);
var ctx = canvas.node().getContext("2d");

ctx.fillStyle = "#f00";

(function tick() {
    ctx.fillRect(10, 10, 10, 10);
    ctx.translate(10, 10);
    setTimeout(tick, 500);
})();

I'm continuously drawing rects, while moving the old rects out of site.

Observation

Suggested by @meagar, I tried Chrome profiler, it seems the out-of-view objects don't consume memory.

Upvotes: 2

Views: 142

Answers (1)

markE
markE

Reputation: 105015

Yes and No.

Yes, the CPU will process the javascript which draws your rectangles.

No, the GPU will not attempt to draw rectangles that are totally off the canvas.

Upvotes: 2

Related Questions