How to overcome memory issue?

You’re right that the issue is Java / Spark. You’ll need to set PYSPARK_SUBMIT_ARGS as described here.