lein help trampoline
states:
Run a task without nesting the project's JVM inside Leiningen's.
Calculates the Clojure code to run in the project's process for the
given task and allows Leiningen's own JVM process to exit before
running it rather than launching a subprocess of Leiningen's JVM.
Use this to save memory or to work around stdin issues.
Arguments: ([task-name & args])
So you can see, without trampoline
the second JVM runs as a sub-process of the first. That's why the first one can't exit — exiting would disrupt the second.
On the other hand, with trampoline
the first JVM constructs a shell script which is then executed by the lein
script to spawn the second JVM. So in this case, the second JVM is a child of the lein
script. How Clojure Babies are Made: Leiningen's Trampoline covers this in quite a bit of detail.
As to why trampoline
is not the default, I'm not entirely sure. But remember that not every lein
command runs project code, so the second JVM is not needed for every command.
Also, there may be disadvantages to using trampoline
. For example, take a look at the following lines of code from the above article:
# Just don't change :target-path in project.clj, mkay?
TRAMPOLINE_FILE="target/trampolines/$INPUT_CHECKSUM"
To me, that implies that there could be problems if :target-path
is set in project.clj
.
lein
starts a separate JVM, there are plenty of reasons to do so. By why keeping original JVM running for the whole time? – Energidtrampoline
works and when it should be used. But it doesn't answer the question why not always usetrampoline
. – Energid