Environment:spring boot 2.5.4 + jdk8 Create a bean to continue load class which could not be found,than use java -jar start springboot fatjar

@Component
public class TestClass implements InitializingBean {
    @Override
    public void afterPropertiesSet() throws Exception {
        new Thread(() -> {
            while (true) {
                try {
                    Class.forName("com.test.error.NotClassFound");
                } catch (ClassNotFoundException e) {
                    //ignore
                }
            }
        }).start();
    }
}

many org.springframework.boot.loader.jar.JarFileWrapper will be create which increase FinalReference time in gc: 20210917132511

when update spring boot version to 2.1.13,it's ok: 20210917132520

In normal it will not happen because LaunchedURLClassLoader has package cache,but it will happen when so bug trigger many nonexistent class load.

Comment From: wilkinsona

Thanks for the report. I have reproduced the behaviour that you have described. I suspect that the changes for https://github.com/spring-projects/spring-boot/issues/22991 are the cause. It was intended to fix a problem that's specific to Java 11 but it looks as if it may have regressed things on Java 8. Running on Java 8, the peak memory footprint of JarFileWrapper is around 10x the peak that I see on Java 11.

Comment From: wilkinsona

This may have been reported previously in https://github.com/spring-projects/spring-boot/issues/23505 but there wasn't enough information to diagnose the problem.

Comment From: wilkinsona

@philwebb What's your take on this one? Short of having different code for Java 8 and Java 11 (which is tricky as we're sub-classing), I'm not sure what the best approach is here.

Comment From: philwebb

I'm really not sure how to fix this one. We do have #26745 open as well.

Comment From: philwebb

@wilkinsona would you mind checking this fix to see if it works with your sample. I think it's working when I try it both on Java 11 and 8.

Comment From: wilkinsona

👍 LGTM.

Comment From: fankaifeng

hello,I had the same problem, What should I do

Comment From: wilkinsona

@fankaifeng As far as we know, this problem was fixed in Spring Boot 2.4.12. If you're using a newer version of Spring Boot and the problem is still occurring, please open a new issue and provide a complete yet minimal sample that reproduces it.

Comment From: fankaifeng

Why is the problem version 2.5.4 raised by HzjNeverStop not compatible after 2.4.12, our version is 2.3.12.RELEASE, do not want to upgrade, how to solve it

Comment From: bclozel

@fankaifeng it's been fixed in 2.5.6 as well, see #28356. Spring Boot 2.3.x has been out of open source support for 2+ years and of commercial support for a year now. We won't release new 2.3.x versions; please upgrade to a supported Spring Boot version.

Comment From: helloworldtang

2.5.2 also have the problem: org.springframework.boot.loader.jar.JarFileWrapper may cause many FinalReference when running on Java 8

jdk version: 1.8.0_144 spring boot:2.5.2

from dump :
SpringBoot JarFileWrapper may cause many FinalReferences causing GC pressure

SpringBoot JarFileWrapper may cause many FinalReferences causing GC pressure

Comment From: wilkinsona

@helloworldtang That is to be expected as this issue was not fixed until 2.5.6.