Changeset 134627 in webkit


Ignore:
Timestamp:
Nov 14, 2012, 10:48:59 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: keep track of mutation observers and disconnect them upon upload
https://bugs.webkit.org/show_bug.cgi?id=102239

Reviewed by Vsevolod Vlasov.

Otherwise we hit memory leaks.

  • inspector/front-end/DefaultTextEditor.js:

(WebInspector.DefaultTextEditor.prototype.wasShown):
(WebInspector.DefaultTextEditor.prototype.willHide):
(WebInspector.TextEditorMainPanel.prototype._wasShown):
(WebInspector.TextEditorMainPanel.prototype._willHide):
(WebInspector.TextEditorMainPanel.prototype._attachMutationObserver):
(WebInspector.TextEditorMainPanel.prototype._detachMutationObserver):

  • inspector/front-end/utilities.js:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r134620 r134627  
     12012-11-14  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: keep track of mutation observers and disconnect them upon upload
     4        https://bugs.webkit.org/show_bug.cgi?id=102239
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        Otherwise we hit memory leaks.
     9
     10        * inspector/front-end/DefaultTextEditor.js:
     11        (WebInspector.DefaultTextEditor.prototype.wasShown):
     12        (WebInspector.DefaultTextEditor.prototype.willHide):
     13        (WebInspector.TextEditorMainPanel.prototype._wasShown):
     14        (WebInspector.TextEditorMainPanel.prototype._willHide):
     15        (WebInspector.TextEditorMainPanel.prototype._attachMutationObserver):
     16        (WebInspector.TextEditorMainPanel.prototype._detachMutationObserver):
     17        * inspector/front-end/utilities.js:
     18
    1192012-11-14  Sergio Villar Senin  <svillar@igalia.com>
    220
  • trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js

    r134591 r134627  
    561561        this._boundSelectionChangeListener = this._mainPanel._handleSelectionChange.bind(this._mainPanel);
    562562        document.addEventListener("selectionchange", this._boundSelectionChangeListener, false);
    563         this._mainPanel._attachMutationObserver();
     563        this._mainPanel._wasShown();
    564564    },
    565565
     
    572572    willHide: function()
    573573    {
    574         this._mainPanel._detachMutationObserver();
     574        this._mainPanel._willHide();
    575575        document.removeEventListener("selectionchange", this._boundSelectionChangeListener, false);
    576576        delete this._boundSelectionChangeListener;
     
    12401240
    12411241WebInspector.TextEditorMainPanel.prototype = {
     1242    _wasShown: function()
     1243    {
     1244        this._isShowing = true;
     1245        this._attachMutationObserver();
     1246    },
     1247
     1248    _willHide: function()
     1249    {
     1250        this._detachMutationObserver();
     1251        this._isShowing = false;
     1252    },
     1253
    12421254    _attachMutationObserver: function()
    12431255    {
     1256        if (!this._isShowing)
     1257            return;
     1258
    12441259        if (this._mutationObserver)
    12451260            this._mutationObserver.disconnect();
    1246         this._mutationObserver = new WebKitMutationObserver(this._handleMutations.bind(this));
     1261        this._mutationObserver = new NonLeakingMutationObserver(this._handleMutations.bind(this));
    12471262        this._mutationObserver.observe(this._container, { subtree: true, childList: true, characterData: true });
    12481263    },
     
    12501265    _detachMutationObserver: function()
    12511266    {
     1267        if (!this._isShowing)
     1268            return;
     1269
    12521270        if (this._mutationObserver) {
    12531271            this._mutationObserver.disconnect();
  • trunk/Source/WebCore/inspector/front-end/utilities.js

    r128281 r134627  
    867867    window.eval(xhr.responseText + "\n//@ sourceURL=" + scriptName);
    868868}
     869
     870
     871/**
     872 * Mutation observers leak memory. Keep track of them and disconnect
     873 * on unload.
     874 * @constructor
     875 * @param {function(Array.<WebKitMutation>)} handler
     876 */
     877function NonLeakingMutationObserver(handler)
     878{
     879    this._observer = new WebKitMutationObserver(handler);
     880    NonLeakingMutationObserver._instances.push(this);
     881}
     882
     883NonLeakingMutationObserver._instances = [];
     884
     885NonLeakingMutationObserver.prototype = {
     886    /**
     887     * @param {Element} element
     888     * @param {Object} config
     889     */
     890    observe: function(element, config)
     891    {
     892        if (this._observer)
     893            this._observer.observe(element, config);
     894    },
     895
     896    disconnect: function()
     897    {
     898        if (this._observer)
     899            this._observer.disconnect();
     900        NonLeakingMutationObserver._instances.remove(this);
     901        delete this._observer;
     902    }
     903}
     904
     905if (!window.testRunner) {
     906    window.addEventListener("unload", function() {
     907        while (NonLeakingMutationObserver._instances.length)
     908            NonLeakingMutationObserver._instances[NonLeakingMutationObserver._instances.length - 1].disconnect();
     909    }, false);
     910}
     911
Note: See TracChangeset for help on using the changeset viewer.