thejh / node-assertvanish

[ABANDONED] assert that an object will vanish
MIT License
7 stars 0 forks source link

Does assertvanish find itself in cyclic dependencies? #1

Open crickeys opened 12 years ago

crickeys commented 12 years ago

The following code creates a cyclic assertion. Should it??

io.sockets.on('connection', function (socket) { // setup listeners for this socket
setup_socket_events(socket);
});

function setup_socket_events(socket) { socket.on('disconnect', event_disconnect(socket) ); } function event_disconnect(socket) {

return function() { 
console.log("disconnect");
    // do something with socket
    assertvanish(socket, 5000);
}

}

thejh commented 12 years ago

What's a cyclic assertion? You mean, you're getting an error message about the socket not disappearing from RAM?

thejh commented 12 years ago

You might want to call the gc() function explicitely, like here: https://github.com/LearnBoost/socket.io/blob/master/test/leaks/socket.leaktest.js

crickeys commented 12 years ago

I reran the code with gc() still got the assertion that socket did not disappear from RAM (Cyclic).

However, I think it's actually accurate. Because I was passing socket here:

socket.on('disconnect', event_disconnect(socket) );

I thought I had to but I didn't realize that all the socket.on functions all have a reference to the socket via this. So, I guess I was passing socket via a closure and never released the closure (cause I don't really understand how here) and that caused the leak.

If I changed it to this:

socket.on('disconnect', event_disconnect ); it seems to help. If that makes any sense at all.

thejh commented 12 years ago

Not sure... that should only matter if you have permanent references to those functions, I think...