javascript - Garbage Collection on circular objects? -


in ws node.js server, have when client connects, assigns "user" object websocket object, , inside user object reference websocket object. lets me send data client when know user object (all game logic deals in user objects, not websockets), , lets me client's user information when data comes in websocket object.

i've heard circular objects can cause issues garbage collection never clean them because have references each other, so question is, need make sure when client disconnects, websocket , user objects both removed memory?

also, let me know if i'm going in wrong way! :p


edit: code:

function onconnect(client) {     users.push({connected: true, client: client, name: "", messages: 0});     client.user = users[users.length - 1];     send("please enter username.", [client.user]); } 

you have manually remove closed connections list. otherwise, garbage collector not remove them memory.

function onconnect(client) {   users.push({     connected: true,     client: client,     name: "",     messages: 0   });   client.user = users[users.length - 1];   client.on('close', function(){     //remove closed connection list let garbage collector job.     users.splice(users.indexof(client.user), 1);   });   send("please enter username.", [client.user]); } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -