leak , node.js and motools serverside

94 views
Skip to first unread message

utan

unread,
Mar 11, 2013, 1:11:02 AM3/11/13
to MooTools Users
Hi guys,

I have node application using socket.io and motools server side,
problem is that I seem to be having memory leak and since is server
side I'm not really sure..

When a user connect a new instance of the class is created, see this
code bellow:

// initiate the server
require('./node_modules/mootools');
var io = require('./node_modules/socket.io');

var Server = new Class({
Implements : [process.EventEmitter],

initialize: function(port)
{
this.serverPort = port;
this.server = null;
// let's connect
this.connect();
},
connect : function(){
// connect to socket io
this.server = io.listen(this.serverPort ,{ log: false });

client.on('disconnect', function() {
delete this.server;// doubt should i delete this object after user
has disconnected?
});
}

});

// initiate the server
var app = new Server(80);

My question is , is the class and it's object destroyed when user
disconnect or socket in this case, or we should manually destroy the
class and or objects.. (I am still in the process of learning more,
bear with me).

Should I delete this object on disconnect like so : delete
this.server;

How is the class and objects taking care in server side with motools?

Appreciate your help.

utan

unread,
Mar 11, 2013, 12:28:59 PM3/11/13
to MooTools Users
Anyone?

utan

unread,
Mar 13, 2013, 12:33:38 PM3/13/13
to MooTools Users
Ok, appreciate for reading it..

On Mar 10, 10:11 pm, utan <vcomputado...@gmail.com> wrote:

Arian Stolwijk

unread,
Mar 13, 2013, 12:41:33 PM3/13/13
to mootool...@googlegroups.com
No idea, generally if you want that the garbage collector picks it up, you should make sure that there are no references to it anymore.

I don't really know any reason why MooTools Classes should be any different from traditional JavaScript inheritance (using var Foo = function(){ ... } Foo.prototype.bar = ... stuff).


--

---
You received this message because you are subscribed to the Google Groups "MooTools Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mootools-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



utan

unread,
Mar 13, 2013, 6:40:52 PM3/13/13
to MooTools Users
So you mean, I should manually delete the instance this.server , I am
confused completed...

Arian Stolwijk

unread,
Mar 13, 2013, 7:00:39 PM3/13/13
to mootool...@googlegroups.com
Usually you don't really care, because node/V8 handles memory.

Also from what I see in your code it just creates the Server instance and directly calls the connect method. There is absolutely nothing special about that.

Then you have socket.io. If I recall correctly you add "connection" event listeners on the socket.io server, that are called with the socket object. That socket object can emit the "disconnect" event.

One thing I'm sure about is that you shouldn't destroy the socket.io server object, especially not in the socket disconnect event, because when one socket is disconnected, the others should still continue to work. It actually would keep working because with "delete this.server" you only remove the reference from the Server object to the socket.io server object. (I think, if it would be correct, "this" in the disconnect event listener doesn't even refer to the Server instance).

Besides that it's hard to say what would be the problem without further insight.

utan

unread,
Mar 13, 2013, 8:16:41 PM3/13/13
to MooTools Users
Isn't every user that connect starting a new instance of the class?

if I destroy the socket instance I am effectively destroying just the
user class it started ?

I was thinking every user is different and running his own instance of
the class.. am I right?

Arian Stolwijk

unread,
Mar 13, 2013, 8:33:02 PM3/13/13
to mootool...@googlegroups.com
no, there is only one Server instance.
Just add some console.log()s at various places to get an idea what is happening.

utan

unread,
Mar 13, 2013, 9:31:24 PM3/13/13
to MooTools Users
Ok, understood but the this.server is an instance of the io.listen
method so this should be destroyed when user disconnect.

Oliv

unread,
Mar 14, 2013, 6:49:13 AM3/14/13
to mootool...@googlegroups.com
Hi,

the usual Client/Server process is that :

the server class is persistant, and stores clients and any usefull communication information in an array, which are created/destroyed at will. It is recommended to make a function delete which destroys all references on sub objects before deleting the object itself, to make sure there is no memory leak.

Hope it helped,

Regards, Olivier Gasc

utan

unread,
Apr 11, 2013, 12:47:47 AM4/11/13
to MooTools Users
I am going to reply to myself because the problems was not Motools or
the way I wrote my code, the problem was with socket.io .. and https ,
I've updated to version 0.9.14 and that fixed the leak...

I like to put this as reference for people using Motools Serverside
and socket.io ...

socket.io reference link https://github.com/LearnBoost/socket.io/issues/1015

Regards
Reply all
Reply to author
Forward
0 new messages