Skip to content

Instantly share code, notes, and snippets.

@khalidr
Last active May 22, 2019 20:56
Show Gist options
  • Save khalidr/dbff15b367b966889a9fbe4484452a10 to your computer and use it in GitHub Desktop.
Save khalidr/dbff15b367b966889a9fbe4484452a10 to your computer and use it in GitHub Desktop.
Get an estimate of the number of bytes an object takes up on heap
def size[T <: AnyRef](obj:T) = org.apache.spark.util.SizeEstimator.estimate(obj)
val myObj = new MyObj()
println(s"object size is ${size(myObj)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment