We are implementing a local server which will communicate with the user's browser on the same machine. The server needs to be able to push events to the browser in certain circumstances. I understand that we can use XMLHttpRequest with keep alive on to set up a persistent connection with the server, and the browser can then check periodically for new data or use onReadyStateChange() to get a notification when new data arrives.

What I don't understand is, won't the responseText of the XMLHttpRequest grow constantly more and more events are received from the server, eating up memory? Is there a way to "reset" the responseText to avoid this problem?