What I ask may be a stupid question, so please forgive me for that. So this happens as follows:
List<Boss> bossList = new ArrayList<Boss>(); Boss b = null; for(Employee e : List<Employee> myList){ b = new Boss(); b.setEmployee(e); bossList.add(b); b = null; }
So, in the above scenario, I create a lot of Boss objects and then de-link to them (I know that I do not need to write "b = null", but I did this to clarify my question). In a normal scenario, I would mark their garbage collection by doing this, but since in this scenario I add those Boss objects to the List collection, are they marked for GC or not? If not, why? And how does the List collection work internally to contain links for each added object to avoid garbage collection?
[EDIT]
The scope of the question is limited only to individual Boss objects created in the for loop, given that this method returns a list link to the outside world.
sunny_dev
source share