Free memory after tar push
Change-Id: I6ba5d0bb24b35db330c77d992d6fb37cc8d4155f
diff --git a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXmlTool.kt b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXmlTool.kt
index 483cdb5..28ee4f2 100644
--- a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXmlTool.kt
+++ b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXmlTool.kt
@@ -3331,12 +3331,28 @@
val count = krillOutputCount.incrementAndGet()
LOGGER.fine("Output Krill JSON for $textId ($count total)")
+
+ // Free memory: remove text data from all data structures after successful output
+ freeTextMemory(textId)
} catch (e: Exception) {
LOGGER.severe("ERROR outputting Krill JSON for $textId: ${e.message}")
e.printStackTrace()
}
}
+ // Free memory for a text that has been output
+ private fun freeTextMemory(docId: String) {
+ texts.remove(docId)
+ sentences.remove(docId)
+ tokens.remove(docId)
+ morpho.remove(docId)
+ fnames.remove(docId)
+ metadata.remove(docId)
+ extraFeatures.remove(docId)
+ // krillData is already removed by the caller (either scanner or finalization loop)
+ LOGGER.fine("Freed memory for text $docId")
+ }
+
private fun generateKrillJson(textData: KrillTextData): String {
val sb = StringBuilder()
sb.append("{")