1

I am new to Play Framework. I having been running Play Framework 2.7.x in production mode. Actually in the most simple code:

package controllers

import javax.inject._
import play.api._
import play.api.mvc._


@Singleton
class HomeController @Inject()(cc: ControllerComponents) extends   AbstractController(cc) {


def index() = Action { implicit request: Request[AnyContent] =>
Ok(views.html.index())
}
}

Going to run I noticed that for each request it increased more memory usage. It increased and increased. At a stage with the increase of request incoming the memory using by the app reached at 1Gb. I stopped sending request, but I noticed that the app is not releasing any memory.

My question is - will this app release it's occupied memory and is there any way of doing that without restarting the app?

cchantep
  • 9,118
  • 3
  • 30
  • 41
John
  • 2,633
  • 4
  • 19
  • 34

1 Answers1

7

Play Framework runs on the Java Virtual Machine (JVM). JVM usually does not release memory back to the operating system. The memory can be released but it's a rare thing e.g. Java 12 introduced JEP 346: Promptly Return Unused Committed Memory from G1 but I'm not sure this would be useful for a small 1 GB heap.

JVM is usually configured to have an upper memory consumption limit and will stay under it or throw a variety of OutOfMemoryError when that's not possible. You should configure the JVM so it has an acceptable memory limit for your server and let the GC do the work.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111