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.
Mark