Skip to content

Instantly share code, notes, and snippets.

@dacr
Created July 18, 2013 13:32
Show Gist options
  • Save dacr/6029317 to your computer and use it in GitHub Desktop.
Save dacr/6029317 to your computer and use it in GitHub Desktop.
revisted...
#!/bin/sh
exec scala -deprecation -nocompdaemon "$0" "$@"
!#
def sleep(inSeconds:Int) = Thread.sleep(inSeconds*1000L)
def usedMemoryInMo_sillyimpl() = {
System.gc
sleep(2)
val rt= java.lang.Runtime.getRuntime
(rt.totalMemory - rt.freeMemory)/1024/1024
}
def printmem(msg:String) { println(s"$msg : ${usedMemoryInMo_sillyimpl()}Mb") }
def allocate(szInMb:Int=24) = Array.fill[Byte](1024*1024*szInMb)(util.Random.nextInt(256).toByte)
sleep(5)
printmem("1")
printmem("before testit")
def testit = {
printmem("testit start")
{
printmem("2-1-1")
//val innerAllocated = allocate()
allocate() match {
case x => // do the processing...
}
// NOT FREEABLE !
printmem("2-1-2")
sleep(10)
printmem("2-1-3")
"done"
}
// NOT FREEABLE !
printmem("testit outside inner block")
println("ready for a heap dump, waiting 100s")
sleep(100)
printmem("testit end")
}
testit
// FREEABLE NOW
printmem("aftertestit")
printmem("4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment