Merge pull request #2470 from ajaxorg/fix/leak

Fix memory leak
This commit is contained in:
Harutyun Amirjanyan 2015-05-07 01:28:22 +04:00
commit 6d205a8f7e
3 changed files with 65 additions and 5 deletions

View file

@ -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>

View file

@ -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 = {

View file

@ -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;