alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (memleak2_actor.scala)

This example Scala source code file (memleak2_actor.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

a, a, array, endme, endme, free, k, long, m, nil, outer, outer, start, start

The Scala memleak2_actor.scala source code

import scala.actors._
import Actor._

case object Start
case object EndMe

class A extends Actor {
  def act = loop {
    react {
      case Start =>
      case EndMe =>
        exit()
    }
  }
}

object Test {

  def z(in: Long) = if (in / 1024L == 0L) in
                    else if (in / (1024L * 1024L) == 0L) (in / 1024L).toString + "K"
                    else (in / (1024L * 1024L)).toString + "M"

  def main(args: Array[String]) {
    val rt = Runtime.getRuntime()
    for (o <- 1 to 300000) {
      println("Outer [2AN] "+o)
      var a: List[A] = Nil
      for (i <- 1 to 10000) {
        var t = new A
        a = t :: a
        t.start
        t ! Start
      }
      for (act <- a) act ! EndMe
      //rt.gc()
      println("Free "+z(rt.freeMemory())+" total "+z(rt.totalMemory()))
    }
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala memleak2_actor.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.