[SPARK-2529] Clean closures in foreach and foreachPartition.