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 when downloading big files #165

Open
mortie opened this issue May 22, 2016 · 1 comment
Open

Memory leak when downloading big files #165

mortie opened this issue May 22, 2016 · 1 comment

Comments

@mortie
Copy link

mortie commented May 22, 2016

Hi. I'm working on a project to stream video in torrent files, and have encountered an issue: the more of a movie is downloaded, the more memory is used, sometimes resulting in a crash due to out of memory errors. I've taken a heap snapshot, and it points to the bencode library, which I know your library usues.

My project is here: https://github.com/mortie/mmpc-media-streamer/. The file which uses torrent-stream: https://github.com/mortie/mmpc-media-streamer/blob/master/js/kickass-proxy/streamer.js

The heap snapshot file is too big for github, so I put it on my web server: https://d.mort.coffee/file/heapsnapshot.gz

Gunzip that and load it in chrome's profiler, and you'll see system / JSArrayBufferData uses gigabytes of memory. I have very little experience interpreting heap snapshots, but the only file name I found was node_modules/bencode/lib/decode.js

@sploadie
Copy link

sploadie commented Jun 2, 2016

I may be wrong, but it seems you replace the functionality of file.destroy() here:

media.destroy = function() {
  engine.destroy();
  engine = null;
}

Which was originally:

FileStream.prototype.destroy = function () {
  if (this._destroyed) return
  this._destroyed = true
  this.emit('close')
}

As defined by torrent-stream/lib/file-stream.js. Assuming this prevents memory from being freed, this may be you issue. Hope this helps.

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

2 participants