Changeset 134627 in webkit
- Timestamp:
- Nov 14, 2012, 10:48:59 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r134620 r134627 1 2012-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 1 19 2012-11-14 Sergio Villar Senin <svillar@igalia.com> 2 20 -
trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js
r134591 r134627 561 561 this._boundSelectionChangeListener = this._mainPanel._handleSelectionChange.bind(this._mainPanel); 562 562 document.addEventListener("selectionchange", this._boundSelectionChangeListener, false); 563 this._mainPanel._ attachMutationObserver();563 this._mainPanel._wasShown(); 564 564 }, 565 565 … … 572 572 willHide: function() 573 573 { 574 this._mainPanel._ detachMutationObserver();574 this._mainPanel._willHide(); 575 575 document.removeEventListener("selectionchange", this._boundSelectionChangeListener, false); 576 576 delete this._boundSelectionChangeListener; … … 1240 1240 1241 1241 WebInspector.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 1242 1254 _attachMutationObserver: function() 1243 1255 { 1256 if (!this._isShowing) 1257 return; 1258 1244 1259 if (this._mutationObserver) 1245 1260 this._mutationObserver.disconnect(); 1246 this._mutationObserver = new WebKitMutationObserver(this._handleMutations.bind(this));1261 this._mutationObserver = new NonLeakingMutationObserver(this._handleMutations.bind(this)); 1247 1262 this._mutationObserver.observe(this._container, { subtree: true, childList: true, characterData: true }); 1248 1263 }, … … 1250 1265 _detachMutationObserver: function() 1251 1266 { 1267 if (!this._isShowing) 1268 return; 1269 1252 1270 if (this._mutationObserver) { 1253 1271 this._mutationObserver.disconnect(); -
trunk/Source/WebCore/inspector/front-end/utilities.js
r128281 r134627 867 867 window.eval(xhr.responseText + "\n//@ sourceURL=" + scriptName); 868 868 } 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 */ 877 function NonLeakingMutationObserver(handler) 878 { 879 this._observer = new WebKitMutationObserver(handler); 880 NonLeakingMutationObserver._instances.push(this); 881 } 882 883 NonLeakingMutationObserver._instances = []; 884 885 NonLeakingMutationObserver.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 905 if (!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.