What I am asking might be a stupid question so please pardon me for that. So it goes like this :
List bossList = new ArrayList();
Bos
The Boss
objects will not be collected by the GarbageCollector
because they are still referenced in the code block that you are posted. bossList
is an ArrayList
which has an internal array of Object
thus holding references to those objects which are added to it.
I such a situation not only the references by you are considered but all referneces in all objects involved.
EDIT: Since you are returning the List in your code the objects will not be marked for garbage collection until the list is no longer referenced in your program.