Closed codingmiao closed 11 months ago
Hey there,
AFAIK Janino has no memory leaks that would cause an OutOfMemoryError
, however, some JVMs are notoriously bad when it comes to garbage-collecting classes and class loaders, which probably is what you observe here.
I ran your code example with an adopt_openjdk-11.0.11-9-hotspot on Windows 10, 21H2, and the memory usage stabilizes at 750...800 MB with the JVM default settings, and Janino happily cooks ClassBodyEvaluator
s at approx. 5000/sec.
What OS and JVM are you using? Could you please try some combinations of OS and/or JVM?
CU Arno
I tried switching from JDK 17 to JDK 11 and adjusted the -XX:MaxMetaspaceSize parameter. It seems that the memory usage has improved. I will continue to observe for a while. Thank you.
I have written the following demo, which increases memory usage continuously during runtime until it encounters a memory overflow. Could you please confirm if this demo has a memory leak issue and suggest how to fix it?
Among them, this section of code,
String code = "public long test(){return " + l + ";}";
, is just a demonstration. In reality, it is dynamically passed by the user in a web service. Therefore, caching is not very meaningful. Even if I implement caching, it seems that some classes and objects generated by ClassBodyEvaluator will not be garbage collected. Over time, this will eventually result in a memory overflow.