Skip to content

Commit 6569e8e

Browse files
committed
Fix: Some memory leaks
1 parent fe679d4 commit 6569e8e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

scripts/dom.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
398398
{
399399
let file = fileManager.file(masterFolders[key]);
400400
let files = await file.readDir();
401+
file.destroy();
401402

402403
for(let i = 0, len = files.length; i < len; i++)
403404
{
@@ -522,6 +523,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
522523

523524
let file = fileManager.file(path);
524525
let files = await loadFilesIndexPage(file, animation, path, keepScroll, mainPath);
526+
file.destroy();
525527

526528
if(config.ignoreSingleFoldersLibrary && !fromGoBack && !disableIgnoreSingleFolders && files.length == 1)
527529
{
@@ -607,6 +609,7 @@ async function nextComic(path, mainPath)
607609
{
608610
let file = fileManager.file(mainPath);
609611
let image = await file.images(1, path);
612+
file.destroy();
610613

611614
return image && image.path ? image.path : false;
612615
}
@@ -615,6 +618,7 @@ async function previousComic(path, mainPath)
615618
{
616619
let file = fileManager.file(mainPath);
617620
let image = await file.images(-1, path);
621+
file.destroy();
618622

619623
return image && image.path ? image.path : false;
620624
}
@@ -742,6 +746,8 @@ async function getFolderThumbnails(path)
742746

743747
_images = await _getFolderThumbnails(file, images, _images, path, folderSha);
744748

749+
file.destroy();
750+
745751
poster = _images.poster;
746752
images = _images.poster ? false : _images.images;
747753
}
@@ -754,7 +760,11 @@ async function getFolderThumbnails(path)
754760
let file = fileManager.file(path);
755761
let _images = await file.images(4, false, true);
756762

757-
_getFolderThumbnails(file, images, _images, path, folderSha, true);
763+
await _getFolderThumbnails(file, images, _images, path, folderSha, true);
764+
765+
file.destroy();
766+
767+
return;
758768

759769
}, path, folderSha);
760770
}
@@ -1209,6 +1219,7 @@ async function comicContextMenu(path, fromIndex = true, folder = false, gamepad
12091219

12101220
let file = fileManager.file(path);
12111221
let images = await file.images(2, false, true);
1222+
file.destroy();
12121223

12131224
poster = !Array.isArray(images) ? images.path : false;
12141225

@@ -1318,6 +1329,8 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
13181329
}
13191330
}
13201331

1332+
file.destroy();
1333+
13211334
skipNextComic = await nextComic(path, mainPath);
13221335
skipPreviousComic = await previousComic(path, mainPath);
13231336

@@ -1355,6 +1368,7 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
13551368
{
13561369
let fileImage = fileManager.file(file.path);
13571370
let images = await fileImage.images(4);
1371+
file.destroy();
13581372

13591373
if(images.length > 0)
13601374
{

scripts/file-manager.js

+24
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ var file = function(path) {
144144
for(let i = 10; i < len; i++)
145145
{
146146
let path = compressed[i].path;
147+
this.compressedOpened[path].compressed.destroy();
147148
delete this.compressedOpened[path];
148149
}
149150
}
@@ -526,6 +527,16 @@ var file = function(path) {
526527

527528
return;
528529
}
530+
531+
this.destroy = function() {
532+
533+
for(let path in this.compressedOpened)
534+
{
535+
this.compressedOpened[path].compressed.destroy();
536+
delete this.compressedOpened[path];
537+
}
538+
539+
};
529540
}
530541

531542

@@ -1712,6 +1723,19 @@ var fileCompressed = function(path, _realPath = false) {
17121723
return false;
17131724
}
17141725

1726+
this.destroy = function() {
1727+
1728+
if(this.tar) this.tar.destroy();
1729+
if(this.pdf) this.pdf.destroy();
1730+
1731+
delete this.zip;
1732+
delete this._7z;
1733+
delete this.rar;
1734+
delete this.tar;
1735+
delete this.pdf;
1736+
1737+
}
1738+
17151739
}
17161740

17171741
// Use this to remove generated vector images if window.devicePixelRatio is changed

scripts/reading/render.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var file = false,
1212

1313
async function setFile(_file, _scaleMagnifyingGlass = false)
1414
{
15+
if(file) file.destroy();
16+
1517
file = _file;
1618
if(file) await file.read(); // Try make this from cache
1719

0 commit comments

Comments
 (0)