Skip to content

Commit

Permalink
Killing zombi setInterval-based runner left behind by removed canvases
Browse files Browse the repository at this point in the history
removed elements didn't remove the global scheduled runners. Now the runner removes itself when elem no longer attached to document.
  • Loading branch information
Daniel Dotsenko committed Aug 16, 2012
1 parent 7c4ccee commit 50f7fe3
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/flashcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ var callbacks = {};
// SPAN element embedded in the canvas
var spans = {};

var elementIsOrphan = function(e){
var topOfDOM = false
e = e.parentNode
while (e && !topOfDOM){
topOfDOM = e.body
e = e.parentNode
}
return !topOfDOM
}

/**
* 2D context
* @constructor
Expand Down Expand Up @@ -194,12 +204,16 @@ var CanvasRenderingContext2D = function(canvas, swf) {
this._font = "";

// frame update interval
var self = this;
setInterval(function() {
if (lock[self._canvasId] === 0) {
self._executeCommand();
var self = this
this._executeCommandIntervalID = setInterval(function() {
if (elementIsOrphan(self.canvas)) {
clearInterval(self._executeCommandIntervalID)
} else {
if (lock[self._canvasId] === 0) {
self._executeCommand();
}
}
}, 30);
}, 30)
};

CanvasRenderingContext2D.prototype = {
Expand Down

0 comments on commit 50f7fe3

Please sign in to comment.