One possibility is to persist and unpersist intermediate results. This can be done in memory or on disk. This is if you want to use some results in a loop or fork them spark would not have to do everything all over again.
But there is no free lunch. Everything needs RAM Time and space.
You could unpersist the spark workflow after you are done.