Skip to content

Instantly share code, notes, and snippets.

@notyy
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notyy/83accd051c09fbdf4257 to your computer and use it in GitHub Desktop.
Save notyy/83accd051c09fbdf4257 to your computer and use it in GitHub Desktop.
stream memory
import scala.io.Source
def b2m(byte: Long): String = s"${byte / 1024 /1024}MB"
val runtime: Runtime = Runtime.getRuntime
println(s"max memory ${b2m(runtime.maxMemory())}MB")
println(s"total memory ${b2m(runtime.totalMemory())}")
println(s"init free memory ${b2m(runtime.freeMemory())}")
val file = Source.fromFile("/Users/twer/source/bigdata/data/new2.dat")
var size = 0
//file.getLines().toStream.foreach(_ => size += 1)
//file.getLines().toList.foreach(_ => size += 1)
file.getLines().foreach(_ => size += 1)
println(s"data size: $size")
//println(s"data size: ${file.getLines().toList.size}")
//println(s"data size: ${file.getLines().size}")
//runtime.gc()
println(s"remain total memory ${b2m(runtime.totalMemory())}")
println(s"remain free memory ${b2m(runtime.freeMemory())}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment