diff --git a/core/src/main/scala/org/apache/spark/SparkContext.scala b/core/src/main/scala/org/apache/spark/SparkContext.scala index a1003b7925715..c6f3b7a8494f8 100644 --- a/core/src/main/scala/org/apache/spark/SparkContext.scala +++ b/core/src/main/scala/org/apache/spark/SparkContext.scala @@ -1032,7 +1032,15 @@ class SparkContext( * (removes unreferenced variables in $outer's, updates REPL variables) */ private[spark] def clean[F <: AnyRef](f: F): F = { - ClosureCleaner.clean(f) + clean(f, true) + } + + /** + * Clean a closure to make it ready to serialized and send to tasks + * (removes unreferenced variables in $outer's, updates REPL variables) + */ + private[spark] def clean[F <: AnyRef](f: F, checkSerializable: Boolean): F = { + ClosureCleaner.clean(f, checkSerializable) f }