[jvm-packages] Prevent dispose being called on unfinalized JBooster (#3005)
* [jvm-packages] Prevent dispose being called twice when finalize * Convert SIGSEGV to XGBoostError * Avoid creating a new SBooster with the same JBooster * Address CR Comments
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
|
||||
package ml.dmlc.xgboost4j.scala
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
import com.esotericsoftware.kryo.io.{Output, Input}
|
||||
import com.esotericsoftware.kryo.{Kryo, KryoSerializable}
|
||||
import ml.dmlc.xgboost4j.java.{Booster => JBooster}
|
||||
@@ -204,11 +202,6 @@ class Booster private[xgboost4j](private[xgboost4j] var booster: JBooster)
|
||||
booster.dispose()
|
||||
}
|
||||
|
||||
override def finalize(): Unit = {
|
||||
super.finalize()
|
||||
dispose
|
||||
}
|
||||
|
||||
override def write(kryo: Kryo, output: Output): Unit = {
|
||||
kryo.writeObject(output, booster)
|
||||
}
|
||||
|
||||
@@ -66,7 +66,12 @@ object XGBoost {
|
||||
// we have to filter null value for customized obj and eval
|
||||
params.filter(_._2 != null).mapValues(_.toString.asInstanceOf[AnyRef]).asJava,
|
||||
round, jWatches, metrics, obj, eval, earlyStoppingRound, jBooster)
|
||||
new Booster(xgboostInJava)
|
||||
if (booster == null) {
|
||||
new Booster(xgboostInJava)
|
||||
} else {
|
||||
// Avoid creating a new SBooster with the same JBooster
|
||||
booster
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user