Why is this a compiler crash?

I have this code:

var nodeMap:Map[Int, List[Node]] = Map[Int, List[Node]]()

nodeMap = Map[Int, List[Node]]() ++ nodes.par.groupBy( x => x.getClosest(centers))

      

x.getClosest returns an Int value. When I go to compile this, the compiler gives out out of memory message. However, when I do this:

var nodeMap:Map[Int, List[Node]] = Map[Int, List[Node]]()

nodeMap = nodes.groupBy( x => x.getClosest(centers))

      

It works great.

Why?

+3


source to share


1 answer


The Scala compiler has some problems with complex expressions; if you run out of some memory (for example OutOfMemoryException), it is more of an error, however more often it happens that the compiler is running out of stack space, in which case you can add a flag -Xss=256m

(where the number is clearly up to you) to fix the problem. This is especially true for complex expressions (for example, string and list concatenations).



+5


source







All Articles