Hello,
I am reading the
SCJP 6.0 Certification book from Kerry and Kathy and I have a doubt I can't clarify with the book info. I googled but I didn't found any info about that. My question is about the JVM garbage collector.
For example, if I have a method like this:
public void getData() {
StringBuilder sb = new StringBuilder();
}
The book explains this: "local variables are in the stack and instance variables / objects in the heap. When a method finalizes and returns: local variables are eligible for garbage collection", but my question is: what about the object instantiated in the method ? Is automatically eligible for garbage collection also ?
if I have the same example but in a for statement like this:
for (int i=0; i <1000; i++) {
StringBuilder sb = new StringBuilder();
}
StringBuilder object is elegible for garbage collection when the for loop finish ?
Thanks
Chris