I have a case where each Akka cluster node (JVM) has one single actor responsible for creating and maintaining (READ/WRITE) a map of some huge objects. Other actors on the same node need to share (READ) the map (the map will be passed into some third-party library, so no way to change the map access by Akka messages).
case class ShareMap(m: Map[String, HugeObject])
class MapOwner extends Actor {
var m: immutable.Map[String, HugeObject] = ???
override def receive: Receive = {
case UpdateMap(delta) =>
val m2 = m ++ delta
this.m = m2
case GetMap =>
sender ! ShareMap(m)
}
}
I want to share the immutable map by sending the map reference to actors within the same JVM.
My question is: for my case (within the same JVM), will it be ensured that no duplicate map object will be created? I have some concerns about the memory usage and performance.
According to the docs
This should be just a reference.