Spring Boot 2.6.14 Nacos 2.1.1 Spring Cloud Context 3.1.5

Use Environment#getProperty to get the configuration center object. Generates a large number of LinkedHashSet objects. Cause the jvm to be full gc.

The code in BootstrapPropertySource is as follows:

@Override
    public String[] getPropertyNames() {
        Set<String> names = new LinkedHashSet<>();
        names.addAll(Arrays.asList(this.delegate.getPropertyNames()));

        return StringUtils.toStringArray(names);
    }

Comment From: Johnson-Jia

The Environment#getProperty method is used inside the for loop.

Comment From: scottfrederick

@Johnson-Jia The code you are referring to in BootstrapPropertySource is part of the Spring Cloud Commons project, and is managed as a separate project from Spring Boot. Please create an issue in the Spring Cloud Commons issue tracker. The Spring Cloud team can provide more help if you provide a complete minimal sample that reproduces the problem you are having.

Comment From: Johnson-Jia

@scottfrederick thank you! I suggest you take a look again. The code call link is as follows. 1676259874383

Comment From: Johnson-Jia

微信图片_20230213114739_看图王

Comment From: Johnson-Jia

@scottfrederick I understand what you mean, but I think there is a problem when SpringBoot uses this method.

Comment From: scottfrederick

I think there is a problem when SpringBoot uses this method.

You mentioned LinkedHashSet, and BootstrapPropertySource in Spring Cloud Commons is the class that is creating LinkedHashSet objects, so I'm not sure how you are coming to the conclusion that Spring Boot is the problem.

Neither the Spring Boot or the Spring Cloud team will be able to provide much assistance without more information about what your application is doing. I would still suggest starting with Spring Cloud Commons, providing a complete minimal sample application that reproduces the problem you are having.

Comment From: Johnson-Jia

OK, thanks

Comment From: Johnson-Jia

I think it should be the Spring Cloud problem, or my usage is wrong.

Use scenarios are as follows: Ten thousand records were queried from the database, and the relevant business logic was executed circularly. The 'getProperty' method was called in the loop, thus a large number of 'propertyNames' configuration objects that could not be recycled were found in the memory snapshot.

Comment From: Johnson-Jia

This should be the reason (https://github.com/spring-projects/spring-boot/issues/34172#issuecomment-1428945752)