I am building a javafx project with scala and I have noticed that the memory usage is over 170mb and a blank javafx project is about 90mb. I saw the JavaFX eats my memory? page and it says that most of the memory in the heap is not being used an explains a way to shrink the heap by using this flag: --XX:+UseG1GC. I tried this in sbt by using: javacOptions += "--XX:+UseG1GC" In Sbt but the memory usage stayed the same. Can anybody help me shrink this heap?
-
If your project is in Scala, I doubt `javacOptions` will do anything. You'll probably have to add it as an option to the `java` command instead – user Oct 16 '20 at 23:11
-
`sbt -mem
` should work. – Ravi Kiran Oct 16 '20 at 23:20
2 Answers
javacOptions
are used to pass Java compiler flags if you have Java filed to compile in your project.
If you are running project from sbt you can set up JVM_OPTS
environment variable or create a .jvmopts
file. They have to be configured this way because when JVM is running it cannot set up its own JVM configs. Although if you want to run program in fork and have sbt use different configs you can use SBT_OPTS
to configure sbt separately from fork.
BTW. If you have some issues you can always use sbt-extras
wrapper which makes things easier. It uses some saner defaults, downloads sbt if it's missing etc.

- 24,995
- 4
- 42
- 64
If you use SBT native packager in you project, in addition to JVM_OPTS
and .jvmopts
you may add flags (or some other custom commands) to a generated execution script. That's how we do it in our project:
project.in(file("example")).settings(
batScriptExtraDefines ++= Seq( //Windows bat/cmd
"""set _JAVA_OPTS=!_JAVA_OPTS! -Djdk.tls.ephemeralDHKeySize=2048""",
"""set _JAVA_OPTS=!_JAVA_OPTS! -Djdk.tls.rejectClientInitiatedRenegotiation=true"""
),
bashScriptExtraDefines ++= Seq( //Unix shell
"""addJava "-Djdk.tls.ephemeralDHKeySize=2048"""",
"""addJava "-Djdk.tls.rejectClientInitiatedRenegotiation=true"""",
"""umask 077"""
)
)

- 96
- 1
- 4