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

Why webtorrent can't release memory after torrent remove? #1104

Closed
catchstar opened this issue Apr 15, 2017 · 3 comments
Closed

Why webtorrent can't release memory after torrent remove? #1104

catchstar opened this issue Apr 15, 2017 · 3 comments

Comments

@catchstar
Copy link

@catchstar catchstar commented Apr 15, 2017

Hey

My code:

const WebTorrent = require('webtorrent');
const client = new WebTorrent();

let magnet = 'magnet:?xt=urn:btih:0EEA3736DD73A5D166BBDF93FF81521E672DF0D1';

const removeTorrent = (magnet) => {
    if(client.get(magnet)){
        client.remove(magnet, ()=>{
            console.log(`remove right`);
        });
    }
};

client.on('torrent', function (torrent) {
    // torrent ready
    // console.log(torrent);

    // remove torrent when torrent ready
    removeTorrent(torrent.magnetURI);
});

client.add(magnet);

// when timeout remove magnet
setTimeout(() => {
    removeTorrent(magnet)
}, 100000);

pm2 status:
1
2

after the console show torrent remove it still can't release the memory:
3

After i add some more magnets, my process occur an error because of memory leak.

  • WebTorrent version: 0.98.18
  • Node.js version: v6.10.2

Please help me check this problem. Thanks a lot.

@kocoten1992

This comment has been minimized.

Copy link
Contributor

@kocoten1992 kocoten1992 commented Apr 19, 2017

I trace it to https://github.com/feross/buffer

window.x = new Int8Array(256*1024*1024)
window.x = new Int8Array(256*1024*1024)
window.x = new Int8Array(256*1024*1024)
window.x = new Int8Array(256*1024*1024)

Run it for a few times, memory never release, it could be from chrome end

P/s:

window.x = new ArrayBuffer(256*1024*1024) // same problem
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Apr 21, 2017

Thanks for the issue. I think you should read a bit about how garbage collection works in JavaScript.

Running window.x = new Int8Array(256*1024*1024) will obviously allocate memory that will never be released, since window.x is referring to that memory forever.

I can't reproduce your issue. I ran your example code in Node.js and memory utilization went down after remove was called. Please share the version of Node.js or the browser that you're running your code in.

@feross feross closed this Apr 21, 2017
@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 3, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.