I am relatively new to Scala.
If I have such a design,
sampleFile.map(line => line.map { var myObj = new MyClass(word); myObj.func(); })
I create a MyClass object and do something inside the class method ( func() ). I repeat this for all lines in the file (via map ). So, I create an object at each stage of my iteration (for each line). The scope of myObj will be invalid when I start the next iteration (will they be destroyed at the end of the block or will they be lost in memory?). My doubt is when garbage collection is triggered? Also, is it expensive to create an object at each stage of the iteration? Does this have a performance value when the number of rows increases to 1 million?
garbage-collection memory-management scala jvm
Learningner
source share