How to uncache RDD?

If you want to remove all the cached RDDs, use this ::

for ((k,v) <- sc.getPersistentRDDs) {
  v.unpersist()
}

RDD can be uncached using unpersist()

rdd.unpersist()

source


The uncache function doesn't exist. I think that you were looking for unpersist. Which according to the Spark ScalaDoc mark the RDD as non-persistent, and remove all blocks for it from memory and disk.


If you cache the source data in a RDD by using .cache() or You have declared small memory. or the default memory is used and its about 500 MB for me. and you are running the code again and again,

Then this error occurs. Try clearing all RDD at the end of the code, thus each time the code runs, the RDD is created and also cleared from memory.

Do this by using: RDD_Name.unpersist()