First of all congrats for clearing SCJP
I guess my main question is about anonymous objects and their eligibility for garbage collection. Are these objects not considered eligible for gc if they are in scope i.e. it doesn't matter if there are no explicit references to these objects
IMO garbage collection has nothing to do scope it basically is concerned whether an object on heap is acessible via a reference or not . in the for loop you are creating 10 objects on the heap that basically have no reference to them so even if the main thread is running can you so something like this System.Out.Println(?)
see here in place of ? you need a reference to an object to call its toString() but you dont have one do you?
so you basically cant acess any of the 10 objects so they are eligible for gc
secondly gc is something we cant control we can only request the JVM but JVM is the big boss.If at any point of time the JVM thinks that number of free memory locations are low it will carry out a gc operation it will not wait for your thread to fininsh .
Do correct me if i went wrong somewhere..