/** * Mutation observers leak memory. Keep track of them and disconnect * on unload. * @constructor * @param {function(Array.<WebKitMutation>)} handler */ function NonLeakingMutationObserver(handler) { this._observer = new WebKitMutationObserver(handler); NonLeakingMutationObserver._instances.push(this); if (!NonLeakingMutationObserver._unloadListener) { NonLeakingMutationObserver._unloadListener = function() { while (NonLeakingMutationObserver._instances.length) NonLeakingMutationObserver._instances[NonLeakingMutationObserver._instances.length - 1].disconnect(); }; window.addEventListener("unload", NonLeakingMutationObserver._unloadListener, false); } }