= i } sc.parallelize(1 to 100 * 1000 * 1000, 1).map { i => new DummyObject(i) // new object every record obj.toInt } sc.parallelize(1 to 100 * 1000 * 1000, 1).mapPartitions { iter => val obj = new DummyObject(0) // reuse the same object iter.map { i => obj.i = i obj.toInt } }