I have a single spring bean similar to the following:
public class MyServiceImpl {
private MyDAO myDAO;
public class MyInnerClass implements SomeInterface<MyInnerClass> {
@Override
public MyInnerClass loadFreshObject(final String key) {
return myDAO.load(key);
}
}
}
Instances of MyInnerClass
are being created in code outside of the spring bean but no reference to those instances are being kept.
Assuming I have no control over the use of these public non-static inner classes (I know ideally these would be private and static to avoid leaking the reference to 'this'), will the created instances of 'MyInnerClass' be correctly garbage collected?
I have run my own tests on this by overriding the finalize()
and it appears that the instances are correctly being garbage collected, I was just hoping for clarification on this.
Thanks