FastTracks / TheAkkaWay

Akka Chinese Book / What should be included in it?
Apache License 2.0
19 stars 3 forks source link

Actor clean up #33

Open He-Pin opened 7 years ago

He-Pin commented 7 years ago

我有个问题请教下。父actor,可能会创建n多的子actor,但是子actor太多的话,会导致占用内存太多,有没有办法,让没有用到的子actor过一段时间就自动从内存中清除掉?

Ryan-Cui commented 7 years ago

如何判断(或如何得知)一个Actor在内存中是没有用到的呢?

He-Pin commented 7 years ago

@Ryan-Cui 一般的做法都是通过设置接收消息超时来做的,即setReceiveTimeout

http://doc.akka.io/docs/akka/current/scala/actors.html#Receive_timeout

如果一段时间内没有收到消息,就关掉自己,即调用stop(self).