setInterval - Estoura mémoria no Firefox
beleza pessoal?
É o seguinte, estou com um problema chato no firefox por causa do uso do 'setInterval', onde esta havendo o estouro de memória, já procurei na Web por respostas, consegui diminuir a velocidade de alocação de memória, mas mesmo assim depois de um tempo estoura.
Segue o código que estou utilizando:
// Essa primeira parte muda a forma do setInterval trabalhar.
// Retirado de https://developer.mozilla.org/en-US/docs/Web/API/Window.setInterval
// Enable the passage of the 'this' object through the JavaScript timers
var __nativeST__ = window.setTimeout, __nativeSI__ = window.setInterval;
window.setTimeout = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
var oThis = this, aArgs = Array.prototype.slice.call(arguments, 2);
return __nativeST__(vCallback instanceof Function ? function () {
vCallback.apply(oThis, aArgs);
} : vCallback, nDelay);
};
window.setInterval = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
var oThis = this, aArgs = Array.prototype.slice.call(arguments, 2);
return __nativeSI__(vCallback instanceof Function ? function () {
vCallback.apply(oThis, aArgs);
} : vCallback, nDelay);
};
// Nova função setInterval para só iniciar uma nova chamada quando a anterior tiver terminado
// Retirado de http://stackoverflow.com/questions/7499060/setinterval-javascript-are-there-known-bugs
function newSetInterval(f, time) {
setInterval.ids = setInterval.ids || {};
setInterval.idCount = setInterval.idCount || 0;
var that = this,
id = setInterval.idCount++,
// to prevent firefox bug that adds an extra element to the arguments
l = arguments.length - 2;
(function theFn() {
// to prevent firefox bug that adds an extra element to the arguments
var args = [].slice.call(arguments, 0, l);
f.apply(this, args);
setInterval.ids[id] = setTimeout.apply(this, [theFn, time].concat(args));
}).apply(that, [].slice.call(arguments, 2, arguments.length));
return id;
}
Esses métodos diminuiu bastante a alocação de memória, mas não resolveu meu problema, se alguém poder dar uma luz agradeço.
Obs.: Foi mal pelo acento errado no título, se o moderador poder alterar agradeço.
Discussão (3)
Carregando comentários...