Quantcast
Viewing all articles
Browse latest Browse all 1367

Memory leak after actors are tried to be stopped

Hi, I am trying to create actors periodically every 10 minutes, and stopping them after 5 minutes (exception topic actors).

As I analyze from profiler (YourKit), I see that actors are not being garbage collected and have strong references to GC root. So the heap size is growing.

After creating a new actor object, my code schedules to call following commands:

override def receive: Receive = {
    case Start =>
      logger.info(s"$actorName started")

      val (killSwitch, result) = consumer
        .map(message => message.value())
        .groupedWithin(20, 5.seconds)
        .mapAsync(5)(processMessage)
        .viaMat(KillSwitches.single)(Keep.right)
        .toMat(Sink.seq)(Keep.both)
        .run()

      consumerBase = result
      consumerKillSwitch = killSwitch

    case Stop =>
      logger.info(s"$actorName stopped")

      system.stop(self)
      context.stop(self)
      consumerKillSwitch.shutdown()
      self ! Kill
  }

What are the best practices to kill/terminate actors so that they can be collected by GC?

Versions used :
akka-actor = "2.6.13"
akka-stream = "2.6.13"
alpAkka = "2.0.7"

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 1367

Trending Articles