Java loading and unloading .java files dynamically, garbage collection?

天大地大妈咪最大 提交于 2019-11-30 02:12:07

You seem to be using the application's default classloader to load the compiled classes - that makes it impossible for the classes to be garbage collected.

So you have to create a separate classloader for your freshly compiled classes. This is how app servers do it.

However, even if you use a separate classloader for your compiled classes, it can be tricky to get those classes to be picked up by garbage collection, because the classloader and all the classes it loaded are not eligible for garbage collcetion as long as a single instance of any of those classes is referred to anywhere else (i.e. the rest of your application).

This is known as a classloader leak and a common problem with appservers, causing redeployments to use ever more memory and eventually fail. Diagnosing and fixing a classloader leak can be very tricky; the article has all the details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!