I can't seem to be able to reopen channels in my browser without a memory leak on production. The dev_appserver version of the channel doesn't leak.
channel.js appears to create an iframe which then loads further javascript for each channel. When a channel is recreated, it looks like the old iframe is removed from the DOM, and a new iframe is created.
However, the old iframe still hangs around as a "Detached DOM tree", along with the window object and all the code it contains, which adds up to about 1MB per channel.
I've tried to build a pared down example that demonstrates this behavior. "/newtokenapi" is just a handler on the server which creates a new channel and returns a json encoded token.
<html>
<head>
Dine-O Test Page
</head>
<body>
<h1>Test</h1>
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
<script>
var token, channel, socket, oReq;
function onOpen(e) {
console.log("socket opened!");
}
function onError(e) {
console.log("socket error!");
}
function onClose(e) {
console.log("socket closed!");
newChannel();
}
function newChannel() {
oReq = new XMLHttpRequest();
oReq.open("GET", "/newtokenapi", true);
oReq.onload = function (e) {
token = JSON.parse(oReq.response)["token"];
channel = new goog.appengine.Channel(token);
socket = channel.open();
socket.onopen = onOpen;
socket.onerror = onError;
socket.onclose = onClose;
}
oReq.send();
}
newChannel();
setInterval(function () {
console.log("forcing socket close");
socket.close();
}, 30000);
</script>
</body>
</html>
I don't think I see a memory leak in my code (can you find one?), which suggests that it's in the channel.js code (or the subsequently downloaded code).
Has anyone been able to work around this? I'm trying to build a page that can be open for weeks, and this leak definitely crashes tablet browsers after a while.
This was a bug in the GAE Channel API Javascript. Apparently it's fixed now, but I haven't verified it yet.
https://code.google.com/p/googleappengine/issues/detail?id=9283