Why HandleWrap is not managed by GC?

35 views
Skip to first unread message

贾凯

unread,
Dec 24, 2015, 12:39:31 AM12/24/15
to nodejs
I think nodejs can make HandleWrap to be Persist weak object, so v8 can collect the inaccessible object and close the underlying file descriptor automatically, but why it isn't ?

var net = require('net');
var PORT = 8000;
var tcpServer = net.createServer(function(socket) {
    console.log('new client');
    // after run out of this callback, `socket' becomes inaccessible, so v8 can collect it
});
tcpServer.listen(PORT);

Ben Noordhuis

unread,
Dec 28, 2015, 9:45:33 AM12/28/15
to nod...@googlegroups.com
HandleWraps are strongly persistent precisely so they don't
automatically close when the last reference to them goes away.

In your example, the next major GC would collect |tcpServer| and close
the server if handles were weak.
Reply all
Reply to author
Forward
0 new messages