Unloading Clojure vars from JVM stream space

I am writing a BaseX plugin in Clojure, built in via "lein uberjar" with the Clojure interpreter enabled. This works well for the most part.

However - when launched through an HTTP instance of BaseX, the evaluation is done inside the Jetty thread pool, not with a thread discarded after the client disconnects.

How plugin loading loads Clojure classes through a custom classloader and discards an object instance (AOT-compiled) that acts as the plugin entry point, does not discard the vars placed by Clojure in thread-local space, leaking the loader class causes the PermGen space to ends up being depleted by multiple instances of the Clojure interpreter.

How can this be solved? I can make sensible non-Clojure-specific changes to the BaseX module load / unload mechanism as needed.

+3


source to share


1 answer


This idea may (or may not work):



  • Don't create uberjars, keep Clojure jars separate;

  • push Clojure pushes the classloader hierarchy by putting them on the main BaseX classpath (edit the command line that starts the BasexX server, something like java -cp BaseX.jar;clojure.jar org.basex.BaseXServer

    );

  • Package your plugin as a jar with your code and rely on the Clojure classes already present in the main classpath.

+1


source







All Articles