How to effectively remove all items from a ListBuffer in Scala?

I have a ListBuffer with thousands of items. After the program has performed the calculations, I want to fill it with new data. Is there a way, like in C, with free () to remove it? Or is this a good way to null my ListBuffer and the garbage collector will do all the work?

+4
source share
1 answer

The method cleardoes just that.

scala> val xs = scala.collection.mutable.ListBuffer(1,2,3,4,5)
xs: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3, 4, 5)

scala> xs.clear()

scala> xs
res2: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
+11
source

Source: https://habr.com/ru/post/1610812/


All Articles