Out of memory error in Kotlin when looping through a medium size data set
  
 
     
     
             
                 
 
 
         
         1 
         
 
         
             
         
 
 
 
 
             
 
             
 
     
     
 
 I am running the below loop in Kotlin and is throwing an out of memory error. I am running this for reading the rows in a csv file. Size of "records" is 6422.   fun readCSVFile(filePath: String): List<String> {      val reader = FileReader(filePath)      val records = CSVFormat.DEFAULT.parse(reader)      val rows = mutableListOf<String>()       var output = ""      records.forEach() {          val size = it.size()          for (i in 0 until it.size()-1) {              output = output + it.get(i) + ","          }          output.dropLast(1)          rows.add(output)      }      return rows  }    Below is the exception I get.   Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded  at java.util.Arrays.copyOf(Arrays.java:3332)  at java.l...