The abstractApplicationContext (aplicationContext interface for that matter) was still NOT null. The number of beans alive was still the same, as was before calling destroySingletons(), destroy(), close() API.
My goal is to dispose the bean instances themselves.
No clean-up is necessary in any bean (e.g. by writing destroy-method in XML) as these beans do not hold reference to anything like datasource etc.
But I just want to remove all the initialized singleton Spring beans. The Spring beans are not lazy, they are all Singleton, do not have destroy-method in XML, neither do implement DisposeBean interface.
I was thinking that one of the following API would remove the beans from scope and will also make application context null. API referring to are:
Please do not duplicate post. This is a duplicate of a newer thread you created, and since the other has more information, I am going to close this one.
usually, just calling close() on your ApplicationContext is enough to remove the beans. But if you internally have references to any of those beans, then it wouldn't be garbage collected. And on that note, you are not guaranteed on when garbage collection does happen, so maybe your code is checking too quickly.