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. When I go to compile this, the compiler crashes saying it’s out of memory. However, when I do this:
var nodeMap:Map[Int, List[Node]] = Map[Int, List[Node]]()
nodeMap = nodes.groupBy( x => x.getClosest(centers))
It works fine.
Why?
The Scala compiler has some issues with complex expressions; if you ran out of memory proper (i.e. OutOfMemoryException) it’s likely a bug, however it is more often the case that the compiler runs out of stack space, in which case you can add the flag
-Xss=256m(where the number is obviously up to you) to work around the problem. This is particularly common with complex expressions (string and list concatenations, for example).