Does assertvanish find itself in cyclic dependencies? #1

Open
crickeys opened this Issue Jan 12, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@crickeys

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

This comment has been minimized.

Show comment Hide comment
@thejh

thejh Jan 12, 2012

Owner

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

Owner

thejh commented Jan 12, 2012

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

@thejh

This comment has been minimized.

Show comment Hide comment
@thejh

thejh Jan 12, 2012

Owner

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

Owner

thejh commented Jan 12, 2012

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

This comment has been minimized.

Show comment Hide comment
@crickeys

crickeys Jan 13, 2012

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.

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

This comment has been minimized.

Show comment Hide comment
@thejh

thejh Jan 13, 2012

Owner

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

Owner

thejh commented Jan 13, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment