[Solved] Java Anonymous Object and Garbage collection part -2


Amit i’ve seen your other question, what matters is always only reachability, it doesn’t matter how you use student, it will always be reachable until the class that contains it is reachable.

Update, regarding the question you added:

I mean which case (CASE-1/CASE-2) is more GC efficient in terms of Time?

Neither because you do the same thing in both functions and remember that you can’t really know when your objects will be collected, and it doesn’t even matter for this kind of examples.

Read this description of how GC works: http://www.cubrid.org/blog/dev-platform/understanding-java-garbage-collection/

Edited: Should learn to read the questions, read this revision of my answer, sorry Amit.

3

solved Java Anonymous Object and Garbage collection part -2