DEV Community

Discussion on: Use Closures for Memory Optimizations in JavaScript (a case study)

Collapse
 
matiaslopezd profile image
Matías López Díaz • Edited

What do you think in this case with socket.io?

namespace.on('connection', socket => new EventRouter(socket));
Enter fullscreen mode Exit fullscreen mode

If I'm not wrong, every time a user connect to Websocket, will be create a new instance of EventRouter. If the user disconnect, the garbage collector will destroy that instance of EventRouter.