In JavaScript, when you do something like this,
function connect() {
    var ws = new WebSocket(url);
    ws.onmessage = function(e) {
        window.alert(e.data);
    };
}
it will work. But why is that?
You would expect that after the connect() function exits, that local ws object goes out of scope and is garbage collected. But in JavaScript, this does not happen.
So does it have something to do with the ws object having event listeners attached to it? Or what is the reason the object continues to stay in memory?
