From 3fadfe2ceae667d56c3c88c9a388bc050867f195 Mon Sep 17 00:00:00 2001 From: Flameish Date: Mon, 7 Sep 2020 22:43:13 +0200 Subject: [PATCH] Improve garbage collection --- src/main/java/grabber/Chapter.java | 38 +++++++++++++++++------------- src/main/java/grabber/EPUB.java | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/grabber/Chapter.java b/src/main/java/grabber/Chapter.java index e6a5e43..137dfe5 100644 --- a/src/main/java/grabber/Chapter.java +++ b/src/main/java/grabber/Chapter.java @@ -21,7 +21,8 @@ */ public class Chapter implements Serializable { private static int chapterId = 0; // Used to set unique filenames - public Element chapterContent; + public Element chapterContainer; + public String chapterContent; public Document doc; public String name; public String chapterURL; @@ -48,7 +49,7 @@ public void saveChapter(Novel novel) { ChapterContentScripts.fetchContent(novel, this); // Check for empty content - if (chapterContent == null) { + if (chapterContainer == null) { if(init.gui != null) { init.gui.appendText(novel.window, "[GRABBER]Chapter container (" + novel.chapterContainer + ") not found."); @@ -64,7 +65,6 @@ public void saveChapter(Novel novel) { novel.nextChapterURL = doc.select(novel.nextChapterBtn).first().absUrl("href"); } } - removeUnwantedTags(novel); if (novel.getImages) { @@ -72,15 +72,15 @@ public void saveChapter(Novel novel) { // Remove tags. // Images would be loaded from the host via original href links on the eReader if left in. } else { - chapterContent.select("img").remove(); + chapterContainer.select("img").remove(); } if (novel.displayChapterTitle) { - chapterContent.prepend( + chapterContainer.prepend( "" + name + "
" + EPUB.NL); } - chapterContent.prepend(EPUB.htmlHead); - chapterContent.append( EPUB.NL+EPUB.htmlFoot); + chapterContainer.prepend(EPUB.htmlHead); + chapterContainer.append( EPUB.NL+EPUB.htmlFoot); cleanHtml(); @@ -91,6 +91,10 @@ public void saveChapter(Novel novel) { } System.out.println("[GRABBER]Saved chapter: "+ name); status = 1; + // Improve GC + chapterContent = chapterContainer.toString(); + doc = null; + chapterContainer = null; } /** @@ -99,21 +103,21 @@ public void saveChapter(Novel novel) { */ private void removeUnwantedTags(Novel novel) { // Always remove