In this case two objects will be eligible for garbage collection. One created in line 16 and one created in line 17.
Whenever you are trying to deal with such examples.
1: Draw a heap ( a rectangle)
2: draw every object created and the reference variable pointing to it. In this case since the class A has two reference variables a1 and a2 ,they are the class members. every new object created will have these in the object.
3: The is only one explicit reference variable to the object created in first line of main. Rest all are implicit ones.
4: At line 19 , the reference is made null and there is no reference to the object created on line 16. and hence it is eligible since it doesnt have any direct / indirect reference. The object created on line 17 is referenced by a2 variable of the object created in line 16. Since Object(16) is already eligible for GC , object(17) is also eligible.
I know its confusing . Please try to read the "Islands of isolation" from the KB book.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: How to make the map of object to be garbage collected