Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON.stringify node server memory leak
    primarykey
    data
    text
    <p>In my memory heap snapshot for my node.js server, I noticed I'm leaking a crazy amount of memory because of the string this function produces: </p> <pre><code>User.prototype._friends = function(friends) { this.friends = friends; this.send(JSON.stringify({ type: 'hello', username: this.data('username'), friends: friends })); }; </code></pre> <p>These are the other two send functions. It goes from .send to ._send.</p> <pre><code>User.prototype.send = function(code, message, callback) { this._send('listener', code, message, callback); }; User.prototype._send = function(type, code, message, callback) { if(!message &amp;&amp; typeof code != 'number') { callback = message; message = code; code = 200; } if(typeof message != 'string') message = JSON.stringify(message); if(type == 'connection' &amp;&amp; this.connection) { this.connection.writeHead(code || 200, { 'Content-Type': 'application/json', 'Content-Length': message.length }); this.connection.end(message); message = null; return; } else { if(!this.listeners.length) //???? WHY return this.message_queue.push(arguments); var cx = this.listeners.slice(), conn; this.listeners = []; while(conn = cx.shift()) { conn.writeHead(code || 200, { 'Content-Type': 'application/json', 'Content-Length': message.length }); conn.end(message); } if(callback) { callback(); message = null; } else{//added this in... message = null; return; } } }; </code></pre> <p>The type of message that takes up most memory is "Hello". _friends is called by code in another middleware file that will put information from a php server through Ajax calls. Not sure how relevant that is since the memory leak looks like to be after that step. Any pointers in the right direction would be greatly appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload