Originally posted by Steve Morrow:
I say it's a terrible question because it depends on knowledge of implementation of the Integer.toString(int i) method. GC is about letting the VM manage memory, not about whether or not references are or are not internally maintained by some class.
Can you please explain how does it affects the number of objects created(or GC'ed)if we do consider Integer.toString(int i);
You're right; it's not possible. Well, it *is*, but it's not practical, and certainly not something worth testing. Similarly, you won't be asked those types of questions about GC in relation to factory-type methods like. There will be a clear, unambiguous answer to the question on the test, at least to those who have an understanding of basic concepts of GC in Java.
As far as i think our code will still Provide GC with 11 objects to collect. and the question for GC will always be asked in context to the given code. Otherwise there are many method that create Objects at background and let them be GC'ed, so should we always count those objects as well, while answering the GC questoins.
I dont think it is possible.
I am sorry if I have asked something silly.
11 objects will be GC'ed
When GC runs, does it collects all the objects eligible for collection, or just enough to free the memory.