From 3600d03e2c2e8413fac2d3ba34c7cca23709fc3e Mon Sep 17 00:00:00 2001 From: vraskulin Date: Tue, 28 Feb 2017 11:37:31 +0300 Subject: [PATCH] StringBuilder in a class field may cause memory leaks, it's not GCed, so it's a better way to store all errors just in string field --- .../main/java/mage/cards/decks/importer/DeckImporter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Mage/src/main/java/mage/cards/decks/importer/DeckImporter.java b/Mage/src/main/java/mage/cards/decks/importer/DeckImporter.java index b33821f271..89efd1bfc2 100644 --- a/Mage/src/main/java/mage/cards/decks/importer/DeckImporter.java +++ b/Mage/src/main/java/mage/cards/decks/importer/DeckImporter.java @@ -40,7 +40,8 @@ import org.apache.log4j.Logger; public abstract class DeckImporter { private static final Logger logger = Logger.getLogger(DeckImporter.class); - protected StringBuilder sbMessage = new StringBuilder(); + + protected String errors; protected int lineCount; public DeckCardLists importDeck(String file) { @@ -51,6 +52,7 @@ public abstract class DeckImporter { return deckList; } lineCount = 0; + StringBuilder sbMessage = new StringBuilder(); sbMessage.setLength(0); try { try (Scanner scanner = new Scanner(f)) { @@ -68,11 +70,12 @@ public abstract class DeckImporter { } catch (Exception ex) { logger.fatal(null, ex); } + errors = sbMessage.toString(); return deckList; } public String getErrors(){ - return sbMessage.toString(); + return errors; } protected abstract void readLine(String line, DeckCardLists deckList);