From time to time, I will get
java.lang.OutOfMemoryError: Metaspace error from sbt. I looked around and found a few similar issues logged in Github project for Play, with some comments saying it could be the app not cleaning up its own resources such as DB connection. After looking through my code to make sure I am not leaving anything around, I tested things out with the play-java-starter project
https://github.com/playframework/play-java-starter-example, and I can reproduce this error with it as well.
- Launch sbt and load the starter project in interactive mode
- Run the project with the run command in sbt
- Hit http://localhost:9000 in browser
- Hit enter or cmd D from sbt as soon as the page is loaded. This should keep you in the sbt interactive console
- Repeat step 2 - 4 a few times, and you will get the OOM error. For me, this usually happens after 5 or 6 runs
This will also happen with hot reloading, e.g. instead of hitting cmd D in step 4, make some changes in source code like an extra new line, and hit refresh in browser.
Does anyone run into this same issue?
Patrick