@Scope("singleton")
@Component
public class Instance{
    ......
}

@Component
public class TestService{
    @Resource
    private Instance instance;
    private Instance instance2=new Instance();
}

the native method declared :

public static synchronized native <T> LinkedList<T> getInstances(Class<T> klass);

and call the native method above like this:

LinkedList<Instance> list = getInstances(Instance.class);
System.out.println(list.size());

finally, you get a list of two elements.

If I provide a method that can get all instances in the JVM (including instances created by spring-framework), is this method meaningful ?

Comment From: sbrannen

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Comment From: loongs-zhang

Well, Mr. Brannen, my purpose is to enhance spring-framework. The method can help spring-framework to implement memory analysis just like eclipse memory analyzer tool, or extend the spring-framework's ability to manage more beans (even if the beans is not created by spring-framework).

Comment From: sbrannen

Hi @dragon-zhang,

Thank you for clarifying your intent. I did not originally realize that you were making a proposal for a new feature.

I now understand your objective. Unfortunately the Spring Framework does not aim to provide memory/heap analysis tools as part of the core framework and therefore cannot include such a feature. In light of that, I am declining the proposal.

Comment From: loongs-zhang

Got it, if there is a good idea in the future, I'll  put it up on github and look forward to discussing with you. Maybe I should put more time in fixing bugs in spring-framework.

发自我的iPhone

------------------ Original ------------------ From: Sam Brannen <notifications@github.com> Date: Tue,Feb 16,2021 10:18 PM To: spring-projects/spring-framework <spring-framework@noreply.github.com> Cc: dragon-zhang <1936978077@qq.com>, Mention <mention@noreply.github.com> Subject: Re: [spring-projects/spring-framework] Proposal to introduce a method that can get all instances in the JVM (including instances created by spring-framework) (#26526)

Hi @dragon-zhang,

Thank you for clarifying your intent. I did not originally realize that you were making a proposal for a new feature.

I now understand your objective. Unfortunately the Spring Framework does not aim to provide memory/heap analysis tools as part of the core framework and therefore cannot include such a feature. In light of that, I am declining the proposal.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.