Java classLoader dilemma with locked jars
I was playing around with classLoaders in Java and noticed a strange thing. If a classLoader loads a class from a jar, this jar is locked indefinitely even if you unreference your classLoader. In the below example, the jar contains a class called HelloWorld. What I do is try to load the class contained in the jar via a classLoader which adds the jar dynamically. If you set skip to true and do not call Class.forName , you can delete the jar but if you do not skip and even if you unreference the classLoader ( classLoader = null ), the jar cannot be deleted until the JVM exits. Why is that? PS: I