by ayewo · 2y ago · 0 comments
1. I’m having a bit of trouble parsing this paragraph:
> The reason eval loads a new classloader every time is justified as dynamically generated classes cannot be garbage collected as long as the classloader is referencing to them. In this case, single classloader evaluating all the forms and generating new classes can lead to the generated class not being garbage collected.
To avoid this, a new classloader is being created every time, this way once the evaluation is done. The classloader will no longer be reachable and all it’s dynamically loaded class.
It sounds like the solution they adopted was to instantiate a brand new classloader each time a dynamic class is evaluated, rather than use a singleton classloader for the app’s lifetime.
Initial Clojure implementation was checking for an already created classloader and tried to reuse. They had commented out the code that was doing it.
Link to the code in the compiler: https://github.com/clojure/clojure/blob/clojure-1.11.0/src/j...
Not sure why they have that if statement that always evaluates to true:
if(true)//!LOADER.isBound())
I usually prefer using the GitHub permalink [1] as it is easy for the line number to go out of sync.[1] https://github.com/clojure/clojure/blob/f376cf62bb0c30f72b0d...
I was confused too (and I may still be) but that's now how I understood their solution.
Their solution, IIUC from reading TFA, is that they simply didn't use eval at all anymore. So the whole "eval loads a new classloader" thinggy (so that it can be GC'ed later on) is totally moot.