In Scala or Java, how do I get how much RAM the application currently takes?

NetBeans IDE has a taskbar pointer that shows how much RAM is allocated and used by the current instance. How can I get this data in my application written in Scala? If there is no special function in Scala for this, I could use Java one.

+7
java scala memory jvm jmx
source share
2 answers
private val runtime = Runtime.getRuntime() import runtime.{ totalMemory, freeMemory, maxMemory } System.out.println("New session, \ total memory = %s, max memory = %s, free memory = %s".format( totalMemory, maxMemory, freeMemory)) 

Just copied from http://harrah.github.com/browse/samples/compiler/scala/tools/nsc/CompileServer.scala.html

+11
source share

You can use totalMemory and maxMemory from the java.lang.Runtime class or use MemoryMXBean .

+3
source share

All Articles