Skip to content

Commit

Permalink
do not retain ref to the first editor (fixes #2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Apr 26, 2015
1 parent 0dcb128 commit a842dcd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 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>
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 a842dcd

Please sign in to comment.