As for my comment ...
Javascript cannot clear the memory section if something points to it about 2 years ago, someone found an exploit, and it quickly closed, and it works like this:
var someData = ["THIS IS SOME DATA SAY IT WAS THE SIZE OF A SMALL APPLICATION"]; var somePointer = someData[0]; delete someData;
Then they entered the application into somePointer, because it was a reference to a memory location when there was no data. hey presto you have entered the memory.
So, if there is a link, as mentioned above somePointer = someData[0]; , you cannot free memory until you delete someData , so you need to delete all links to everything that you want to clear in your case ALL_CLIENTS.push(this); on line 64, makes your system memory accessible through ALL_CLIENTS, so you can do
Line 157
_.each(ALL_CLIENTS, function(client, i) { var u;
In another note, this is not a memory leak, a memory leak means that you had this server, you close it if the memory is not freed after you left it, then you have a memory leak, if it clears the memory behind it, not a leak, it's just bad memory management.
Thanks to @Magus for pointing out that deleting is not the best thing you could use, but I would never recommend you implement a restrictive structure, but you could try
Line 27: ALL_CLIENTS.unused = 0;
Line 64:
var u; if(ALL_CLIENTS.unused > 0){ for(var i = 0; i < ALL_CLIENTS.length; i++){ if(ALL_CLIENTS[i] == u){ ALL_CLIENTS[i] = this; ALL_CLIENTS.unused--; i = ALL_CLIENTS.length; } } }else{ ALL_CLIENTS.push(this); }
Martin barker
source share