Skip to content

Commit

Permalink
Merge pull request #2470 from ajaxorg/fix/leak
Browse files Browse the repository at this point in the history
Fix memory leak
  • Loading branch information
nightwing committed May 6, 2015
2 parents d2dc26f + d080fe5 commit 6d205a8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
59 changes: 59 additions & 0 deletions experiments/debug_mem_leak.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="../demo/kitchen-sink/require.js"></script>
<script type="text/javascript">
require.config({
paths: { ace: "../lib/ace" },
waitSeconds: 0
});
</script>
</head>
<body>
<p><button onclick="toggleEditor()">Toggle editor</button></p>

<div id="container"></div>
<script>
var editor;
var counter = 0

function toggleEditor() {
if (!editor) {
var root = document.createElement("div");
root.style.height = "100px";
root.setAttribute("id", "editor");
root.textContent = "function foo(items) {\nvar x = 'All this is syntax highlighted';\nreturn x;\n}";

document.getElementById("container").appendChild(root);

editor = ace.edit(root);

if (counter++ % 2)
editor.setTheme("ace/theme/monokai");
else
editor.setTheme("ace/theme/clouds");

editor.session.setMode("ace/mode/javascript");
} else {
editor.destroy();
var el = editor.container;
el.parentNode.removeChild(el);

editor.container = null
editor.renderer = null

editor = null;

var root = document.getElementById("editor")
if (root)
root.parentNode.removeChild(root);
}
}
require(["ace/ace"], function(ace) {
window.ace = ace;
toggleEditor();
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion lib/ace/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var AppConfig = require("./lib/app_config").AppConfig;
module.exports = exports = new AppConfig();

var global = (function() {
return this;
return this || typeof window != "undefined" && window;
})();

var options = {
Expand Down
9 changes: 5 additions & 4 deletions lib/ace/lib/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,14 @@ exports.addCommandKeyListener = function(el, callback) {
});

if (!pressedKeys) {
pressedKeys = Object.create(null);
addListener(window, "focus", function(e) {
pressedKeys = Object.create(null);
});
resetPressedKeys();
addListener(window, "focus", resetPressedKeys);
}
}
};
function resetPressedKeys(e) {
pressedKeys = Object.create(null);
}

if (window.postMessage && !useragent.isOldIE) {
var postMessageId = 1;
Expand Down

0 comments on commit 6d205a8

Please sign in to comment.