fix Spark memory leak (#1157)