Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #2087

Closed
gyzerok opened this issue Apr 17, 2015 · 2 comments
Closed

Memory leak #2087

gyzerok opened this issue Apr 17, 2015 · 2 comments

Comments

@gyzerok
Copy link

gyzerok commented Apr 17, 2015

Following code results in memory leak on the server-side.
Note: For test purposes I run just one tab with test.html.

// server.js
var server = require('http').createServer(handler);
var io = require('socket.io')(server);
server.listen(1338, function () {
  console.log('API started on ' + 1338);
});

var fs = require('fs');
function handler(req: Object, res: Object): void {
  res.writeHead(200);
  res.write(fs.readFileSync(process.cwd() + '/test.html'));
  res.end();
}

io.on('connection', function (socket) {
  socket.on('suggestions', function (cb) {
    cb([]);
  });
});
<!-- test.html -->
<html>
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script>
</head>
<body>
  <script>
    var socket = io('http://127.0.0.1:1338');
    var interval = Math.floor(1000 * 60 / 1000);
    setInterval(function () {
      socket.emit('suggestions', function () {
        console.log('received');
      });
    }, interval);
  </script>
</body>
</html>
@ismriv
Copy link

ismriv commented Aug 4, 2015

Tracking down a memory leak as well, but your case doesn't seem to be causing a leak though. What made you think that?

Added the following to monitor memory usage every 10s:

setInterval(function () {
  global.gc();
  console.error(new Date(), process.memoryUsage());
}, 10000);

And the memory seems stable:

Tue Aug 04 2015 14:18:24 GMT+0000 (UTC) { rss: 22196224, heapTotal: 16571136, heapUsed: 5692824 }
Tue Aug 04 2015 14:18:34 GMT+0000 (UTC) { rss: 22196224, heapTotal: 16571136, heapUsed: 5780352 }
Tue Aug 04 2015 14:18:44 GMT+0000 (UTC) { rss: 22462464, heapTotal: 16571136, heapUsed: 6017816 }
Tue Aug 04 2015 14:18:54 GMT+0000 (UTC) { rss: 22732800, heapTotal: 16571136, heapUsed: 5956968 }
Tue Aug 04 2015 14:19:04 GMT+0000 (UTC) { rss: 22360064, heapTotal: 16571136, heapUsed: 5542240 }
Tue Aug 04 2015 14:19:14 GMT+0000 (UTC) { rss: 22360064, heapTotal: 16571136, heapUsed: 5122096 }
Tue Aug 04 2015 14:19:24 GMT+0000 (UTC) { rss: 22020096, heapTotal: 16571136, heapUsed: 5134072 }
Tue Aug 04 2015 14:19:34 GMT+0000 (UTC) { rss: 22020096, heapTotal: 16571136, heapUsed: 5157920 }
Tue Aug 04 2015 14:19:44 GMT+0000 (UTC) { rss: 22020096, heapTotal: 16571136, heapUsed: 5165752 }
Tue Aug 04 2015 14:19:55 GMT+0000 (UTC) { rss: 22020096, heapTotal: 16571136, heapUsed: 5163072 }
...
Tue Aug 04 2015 15:04:18 GMT+0000 (UTC) { rss: 22491136, heapTotal: 16571136, heapUsed: 5141744 }
Tue Aug 04 2015 15:04:28 GMT+0000 (UTC) { rss: 22491136, heapTotal: 16571136, heapUsed: 5196792 }
Tue Aug 04 2015 15:04:38 GMT+0000 (UTC) { rss: 22491136, heapTotal: 16571136, heapUsed: 5219240 }
Tue Aug 04 2015 15:04:48 GMT+0000 (UTC) { rss: 22491136, heapTotal: 16571136, heapUsed: 5227304 }
Tue Aug 04 2015 15:04:58 GMT+0000 (UTC) { rss: 22491136, heapTotal: 16571136, heapUsed: 5219648 }
Tue Aug 04 2015 15:05:08 GMT+0000 (UTC) { rss: 22491136, heapTotal: 16571136, heapUsed: 5210480 }

@darrachequesne
Copy link
Member

That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@ismriv @gyzerok @darrachequesne and others