我收到以下异常:
java.lang.OutOfMemoryError: GC overhead limit exceeded
使用此堆栈跟踪:
at scala.collection.immutable.HashSet$HashTrieSet.updated0(HashSet.scala:230)
at scala.collection.immutable.HashSet.$plus(HashSet.scala:56)
at scala.collection.immutable.HashSet.$plus(HashSet.scala:33)
at scala.collection.SetLike$$anonfun$$plus$plus$1.apply(SetLike.scala:128)
at scala.collection.SetLike$$anonfun$$plus$plus$1.apply(SetLike.scala:128)
at scala.collection.TraversableOnce$$anonfun$foldLeft$1.apply(TraversableOnce.scala:144)
at scala.collection.TraversableOnce$$anonfun$foldLeft$1.apply(TraversableOnce.scala:144)
at scala.collection.immutable.HashSet$HashSet1.foreach(HashSet.scala:153)
at scala.collection.immutable.HashSet$HashTrieSet.foreach(HashSet.scala:306)
at scala.collection.immutable.HashSet$HashTrieSet.foreach(HashSet.scala:306)
at scala.collection.immutable.HashSet$HashTrieSet.foreach(HashSet.scala:306)
at scala.collection.TraversableOnce$class.foldLeft(TraversableOnce.scala:144)
at scala.collection.AbstractTraversable.foldLeft(Traversable.scala:105)
at scala.collection.TraversableOnce$class.$div$colon(TraversableOnce.scala:138)
at scala.collection.AbstractTraversable.$div$colon(Traversable.scala:105)
at scala.collection.SetLike$class.$plus$plus(SetLike.scala:128)
at scala.collection.AbstractSet.$plus$plus(Set.scala:47)
我将在此处草拟调用++
的代码:
val features = Array[(String, Double)]() ++
featuresExtractor.map {
case (// ...) =>
(featureNameString, featureValueDouble)
}
case (// ...) =>
Option(...)
match {
case None =>
terms.map { term: String => (term, 0.0d) }
case Some(...) =>
terms.map { term: String =>
val value: Option[Double] = ...
(featureName, value.getOrElse(0.0d)
}
}
}.reduce(_ ++ _)
此代码基本上遍历featuresExtractor
(Map
)以生成Array[(String, Double)]
。
我的问题是:过度创建小型对象,GC花了很多时间试图恢复由于我(我只是创建了很多这些),或者这是一个Scala数据结构问题?
接下来将是:我应该放弃reduce
并尝试另一种方法来解决这个问题吗?