zerobias / telegram-mtproto

Telegram client api (MTProto) library
MIT License
620 stars 136 forks source link

memory leaks #110

Closed dmitrdv closed 5 years ago

dmitrdv commented 7 years ago

Hi!

When I try to get full history from several hundreds channels memory size is increase infinitely. And I will get error in some hours. I check this on 3.0.6 and 3.2.11.

This is example of my code which is not save results in any array but size of application in my case increase to 2GB in some hours. Could you please help?

`'use stricts'

const sleep = require('system-sleep'); const { MTProto } = require('telegram-mtproto') const { Storage } = require('mtproto-storage-fs')

const server = { dev: false }

const api = { layer: 57, initConnection: 0x69796de9, api_id: 49631 }

const client = new MTProto({ server, api, app: { storage: new Storage('storage') } });

async function parse(channel, offsetId, client) { const options = { peer: { _: 'inputPeerChannel', channel_id: channel.id, access_hash: channel.access_hash }, limit: 100 };

if (offsetId) { options.offset_id = offsetId; }

return client('messages.getHistory', options); }

async function parseChannel(channel, client) { let offsetId;

do { const res = await parse(channel, offsetId, client);

if (!res || !res.messages || !res.messages.length) {
  break;
}

offsetId = res.messages[res.messages.length - 1].id;

if (offsetId <= 1) {
  break;
}

sleep(1000);

} while (true) }

async function main() { const channels = []; // some long array with channels

for (const i in channels) { await parseChannel(channels[i], client); } }

main();`