Skip to content

Commit

Permalink
#33 fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Last-Order committed Aug 25, 2019
1 parent 4c125dc commit 98993f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minyami",
"version": "2.2.12",
"version": "2.2.13",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 0 additions & 2 deletions src/core/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default class LiveDownloader extends Downloader {
outputFileList: string[] = [];
finishedList: string[] = [];
m3u8: M3U8;
playlists: M3U8[] = [];
chunks: Chunk[] = [];
runningThreads: number = 0;

Expand Down Expand Up @@ -75,7 +74,6 @@ export default class LiveDownloader extends Downloader {

await this.loadM3U8();

this.playlists.push(this.m3u8);
this.timeout = Math.max(20000, this.m3u8.chunks.length * this.m3u8.getChunkLength() * 1000);

if (this.m3u8.isEncrypted) {
Expand Down
9 changes: 8 additions & 1 deletion src/core/m3u8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ export default class M3U8 {

let inHeaderPart = true;
let key: string, iv: string, sequenceId: string;
for (const line of this.m3u8Content.split('\n')) {
for (let line of this.m3u8Content.split('\n')) {
/**
* v8 引擎内部对 split/slice 出的字符串有一个对 parent 的引用
* 并且默认不会被 GC 当 parent string 很长时会造成内存泄漏
* 此处复制了一次字符串避免此情况
* See also: https://github.com/nodejs/help/issues/711
*/
line = line.split('').join('');
if (line.startsWith('#')) {
// it is a m3u8 property
if (line.startsWith('#EXT-X-KEY')) {
Expand Down

0 comments on commit 98993f3

Please sign in to comment.